猿问

vue-v-for的key值为什么会一直重复?

AB是两个tab页,切换的时候已经把addlist致为空数组了,js部分打印index值为啥是undefined?求解


<div class="tit">区域编号 A</div>

      <div class="item" v-for="item in addList" :key="item.index" v-if="addList.length>0">

        <el-input v-model="item.shelves_number" disabled></el-input>

        <el-input v-model="item.shelves_layer" disabled></el-input>

        <el-input v-model="item.shelves_layer_num" disabled></el-input>

        <span>{{item.shelves_num}}</span>

        <span><button @click="delBtn_2(item.index,addList)">删除</button></span>

 </div>


<div class="tit">区域编号 B</div>

      <div class="item" v-for="item in addList" :key="item.index" v-if="addList.length>0">

        <el-input v-model="item.shelves_number" disabled></el-input>

        <el-input v-model="item.shelves_layer" disabled></el-input>

        <el-input v-model="item.shelves_layer_num" disabled></el-input>

        <span>{{item.shelves_num}}</span>

        <span><button @click="delBtn_2(item.index,addList)">删除</button></span>

 </div>

js部分


delBtn_2(index,data){ 

      console.log(index);

      data.splice(index,1);

      this.setList.splice(index,1);


MMTTMM
浏览 2029回答 2
2回答

吃鸡游戏

你的addList里面没有index属性吧

潇潇雨雨

自己加上index,v-for=(item,index) in addList
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答