vue获取当前点击对象的下标,和当前点击对象的内容

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

猜你喜欢

转载自blog.csdn.net/M_SSY/article/details/82897474
今日推荐