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)}}%