素材牛VIP会员
vue.js中列表里面的子元素怎么获取列表的索引index值
 yi***ou  分类:Html5  人气:2627  回帖:1  发布于6年前 收藏

在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>

理想效果


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

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

 标签:html5javascript

讨论这个帖子(1)垃圾回帖将一律封号处理……

Lv6 码匠
li***28 Linux系统工程师 6年前#1
 文明上网,理性发言!   😉 阿里云幸运券,戳我领取