1

I'm working with Vue.JS right now and a status bar and I was wondering how to put data from vue in an html attribute.

<div class="progress">
    <div class="progress-bar" role="progressbar" aria-valuenow="score" aria-valuemin="0" aria-valuemax="100" style="width: 0%;">
        <span class="sr-only">${this.score}% Complete</span>
    </div>
</div>

I already tried this:

<div class="progress">
    <div class="progress-bar" role="progressbar" v-bind:aria-valuenow="score" aria-valuemin="0" aria-valuemax="100" style="width: 0%;">
        <span class="sr-only">${this.score}% Complete</span>
    </div>
</div>

But the v-bind: doesn't work.

2
  • try aria-valuenow="{{ score }} and if you changed the default brackets it will be like aria-valuenow="${score}%" Commented Mar 16, 2017 at 14:11
  • aria-valuenow="{{ score }}" will not work. Interpolation in attributes are now deprecated, instead use v-bind like v-bind:aria-valuenow="score" or :aria-valuenow="score". Commented Mar 16, 2017 at 14:14

1 Answer 1

3

Works for me.

new Vue({
  el: '#app',
  data: {
    score: 20
  }
});
[aria-valuenow="20"] {
  color: red;
}
<script src="//cdnjs.cloudflare.com/ajax/libs/vue/2.2.4/vue.min.js"></script>
<div id="app" class="progress">
  <div class="progress-bar" role="progressbar" v-bind:aria-valuenow="score" aria-valuemin="0" aria-valuemax="100" style="width: 0%;">
    <span class="sr-only">${{this.score}}% Complete</span>
  </div>
</div>

Sign up to request clarification or add additional context in comments.

2 Comments

Hmm, I tried it via your snippet and it worked. Thanks dude!
Also worked for me. Got stuck with binding my value within curly brackets. Removed them and its good now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.