选中项高亮显示
<div style="border: 1px solid red; height: 200px">
<div :class="{'active':index == current}" v-for="(item, index) in data" :key="index" @click="change(index)">{{ item.text }}</div>
</div>
...
current: null,//选中项
data: [{ text: '已关联' }, { text: '未关联' }],
...
change(x) {
console.log(x)
this.current = x
},
思路:
- 遍历数据后,通过点击事件,拿到点击的某一项的索引,赋值给
current,即为当前项。 - 绑定class,如果选中项选中项
current与当前项index对比为true,就展示高亮样式。
该博客介绍了如何使用Vue.js实现选中项高亮显示的功能。通过遍历数据并绑定点击事件,当点击某一项时,将索引赋值给当前选中项current,然后根据current与index的对比来应用高亮样式。内容涉及到Vue的v-for指令、事件处理以及条件类绑定。
474

被折叠的 条评论
为什么被折叠?



