vue.js中列表里面的子元素怎么获取列表的索引index值

在vue.js中用v-for循环代码,怎么使li标签中的子元素获得该li标签的index值

代码:

<li class="posiRela counItem page-infinite-listitem clearfix" v-for="(item, index) in goods">
            <img v-if="item.goodtype === '主机'" src="../../static/images/zhuji_icon.png">
            <img v-if="item.goodtype === '笔记本'" src="../../static/images/computer_icon.png">
            <img v-if="item.goodtype === '服务器'" src="../../static/images/fuwuqi_icon.png">
            <img v-if="item.goodtype === '家具'" src="../../static/images/jiaju_icon.png">
            <img v-if="item.goodtype === '电话机'" src="../../static/images/phone_icon.png">
            <img v-if="item.goodtype === '打印机'" src="../../static/images/printer_icon.png">
            <img v-if="item.goodtype === '手机'" src="../../static/images/tel_icon.png">
            <img v-if="item.goodtype === '投影仪'" src="../../static/images/touying_icon.png">
            <img v-if="item.goodtype === '电视机'" src="../../static/images/TV_icon.png">
            <img v-if="item.goodtype === '显示器'" src="../../static/images/xianshi_icon.png">
            <div class="itemLeft">
              <p class="itemName">[{{item.goodtype}}] {{item.name}}</p>
              <p>资产号:{{item.num}}</p>
              <p>存放地点:{{item.city}}</p>
            </div>
            <i v-if="item.isAdd === false" class="addGood" @click="addGood"></i>
            <i v-else class="minusGood"></i>
          </li>

理想效果

clipboard.png
点击途中i标签能获取到这个li标签的index值

还请各位大神帮忙解答!!谢谢!!

阅读 9k
2 个回答
@click='addGood(index)'
methods:{
    addGood(index){
        console.log(index)
    }

}

如楼上,把index传入你的点击事件就可以获取了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题