<li v-for="(item,index) in tabList" v-on:click="addClass(index,$event)" >{{item.title}}</li>
data里面声明:
data() {
return {
tabList: [
{ id: 0, title: "首页1" },
{ id: 1, title: "首页2" },
{ id: 2, title: "首页3" }
],
current:0
};
},
methods: {
addClass: function(index,event) {
this.current = index;
//获取点击对象
var el = event.currentTarget;
console.log("当前对象的内容:"+el.innerHTML);
console.log(this.current)
}
本文介绍如何在 Vue.js 中使用 v-for 指令遍历列表,并为列表项添加点击事件,同时展示如何通过事件处理函数访问被点击元素及更新数据状态。
2527

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



