在项目中做了上移和下移的事件,数组lists已经被修改了,视图上也正确渲染,但是tap点击事件传送过来的index依然显示错误
<view class="list" v-for="(list,index) in lists" :key="index">
<image class="list-img" :src="'../../../static/img/' + list.image" mode="aspectFit"></image>
<view class="list-text"> {{list.text}} </view>
<view class="list-options">
<view class="down" v-if="index!=lists.length-1" @tap="down(index)"> ↓ </view>
<view class="up" v-if="index!=0" :data-index="index" @tap="up(index)"> ↑ </view>
</view>
</view>
down(index){
let list = this.lists[index];
this.lists.splice(index+2,0,list)
this.lists.splice(index,1)
this.set_payway()
},
up(index){
console.log(index) //此处打印出来发现与视图上的下标不符合
let list = this.lists[index];
this.lists = this.lists.splice(index-1,0,list)
this.lists = this.lists.splice(index+1,1)
},
你这个不是vue,是小程序。
试下重新setData