【发布时间】:2017-08-18 02:05:05
【问题描述】:
我有一个数组(历史),每次按下按钮时都会推送两个项目。这两个项目在打印时需要具有不同的 css 样式。
HTML
<ul class="info">
<li :class="{ 'style-one' : toggle, 'style-two' : toggle }" v-for="item in history">{{item}}</li>
</ul>
JS (Vue)
methods: {
attack: function() {
this.history.unshift(this.playerDamaged);
this.history.unshift(this.monsterDamaged);
}
问题是在循环过程中无法改变toggle 的真实性。有没有更好的方法来解决这个问题?
【问题讨论】: