鍍金池/ 問答/HTML5  HTML/ vue.js中列表里面的子元素怎么獲取列表的索引index值

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

在vue.js中用v-for循環(huán)代碼,怎么使li標(biāo)簽中的子元素獲得該li標(biāo)簽的index值

代碼:

<li class="posiRela counItem page-infinite-listitem clearfix" v-for="(item, index) in goods">
            <img v-if="item.goodtype === '主機(jī)'" src="../../static/images/zhuji_icon.png">
            <img v-if="item.goodtype === '筆記本'" src="../../static/images/computer_icon.png">
            <img v-if="item.goodtype === '服務(wù)器'" src="../../static/images/fuwuqi_icon.png">
            <img v-if="item.goodtype === '家具'" src="../../static/images/jiaju_icon.png">
            <img v-if="item.goodtype === '電話機(jī)'" src="../../static/images/phone_icon.png">
            <img v-if="item.goodtype === '打印機(jī)'" src="../../static/images/printer_icon.png">
            <img v-if="item.goodtype === '手機(jī)'" src="../../static/images/tel_icon.png">
            <img v-if="item.goodtype === '投影儀'" src="../../static/images/touying_icon.png">
            <img v-if="item.goodtype === '電視機(jī)'" 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>資產(chǎn)號(hào):{{item.num}}</p>
              <p>存放地點(diǎn):{{item.city}}</p>
            </div>
            <i v-if="item.isAdd === false" class="addGood" @click="addGood"></i>
            <i v-else class="minusGood"></i>
          </li>

理想效果

clipboard.png
點(diǎn)擊途中i標(biāo)簽?zāi)塬@取到這個(gè)li標(biāo)簽的index值

還請(qǐng)各位大神幫忙解答??!謝謝??!

回答
編輯回答
哎呦喂

如樓上,把index傳入你的點(diǎn)擊事件就可以獲取了

2017年5月31日 08:41
編輯回答
別硬撐
@click='addGood(index)'
methods:{
    addGood(index){
        console.log(index)
    }

}
2018年3月7日 14:30