【发布时间】:2019-02-26 06:05:00
【问题描述】:
我正在制作一个简单的待办事项列表应用程序,并且想知道如何在仅特定的动态v-for 元素上应用样式。
<f7-list-item v-for="(listItem, index) in activeList.listItems" :key="index" :class="(checked) ? 'checked':'not-checked'">
{{ index+1 }}. {{ listItem }}
<span @click="checkTaskDone(index)">
<i class="f7-icons" id="check-task-btn">check_round</i>
</span>
</f7-list-item>
export default {
data() {
return {
checked: false
}
},
methods: {
checkTaskDone(item) {
if (this.checked == false) {
this.checked = true;
} else if (this.checked == true) {
this.checked = false;
}
}
}
}
.checked {
text-decoration: line-through;
color: #444;
}
使用此代码,它将类添加到每个v-for 列表元素中,而不管单击了哪个元素,正如预期的那样。我想知道处理这个问题的最佳方法是什么。我已经尝试从 index 制作一个道具,并尝试以它为目标来应用样式,但我无法让它发挥作用。
提前致谢!
【问题讨论】:
标签: javascript css list vue.js html-framework-7