Javascript Vue.js进度条
我使用的是Javascript Vue.js进度条,javascript,css,twitter-bootstrap,vue.js,Javascript,Css,Twitter Bootstrap,Vue.js,我使用的是vue.js2.0我得到了以下方法: calculatePercentage(option) { let totalVotes = 0; this.poll.options.forEach((option) => { totalVotes+= option.votes.length; }); return option.votes.length / totalVotes * 100; } 这是我的引导进度条: <div
vue.js2.0
我得到了以下方法:
calculatePercentage(option) {
let totalVotes = 0;
this.poll.options.forEach((option) => {
totalVotes+= option.votes.length;
});
return option.votes.length / totalVotes * 100;
}
这是我的引导进度条:
<div class="span6">
<div v-for="option in poll.options">
<strong>{{ option.name }}</strong><span class="pull-right">{{ calculatePercentage(option) }}%</span>
<div class="progress progress-danger active" aria-valuenow="12">
<div class="bar" style="width: 15%;"></div>
</div>
</div>
</div>
{{option.name}{{calculatePercentage(option)}}%
因此,calculatePercentage(选项)代码>工作正常。但是如何将其绑定到样式(style=“width:15%;”
)呢
非常感谢如前所述,您可以将内联样式绑定到vue数据。您只需从calculatePercentage
返回值,并以如下方式使用它:
<div class="span6">
<div v-for="option in poll.options">
<strong>{{ option.name }}</strong><span class="pull-right">{{ calculatePercentage(option) }}%</span>
<div class="progress progress-danger active" aria-valuenow="12">
<div class="bar" v-bind:style="{width: calculatePercentage(option) + '%'}"></div>
</div>
</div>
</div>
{{option.name}{{calculatePercentage(option)}}%