2 回答
TA贡献1826条经验 获得超6个赞
可以watch整个item嘛。
computed的话可以返回更新后的结果组成的数组再v-for组件。
提供个粗糙的思路哈
computed:{
value(){
return this.item.map((item)=>{
if(item){
//触发更新函数
return update()
} else {
return <未更新的值>
}
})
}
}
然后 v-for="value"
TA贡献1851条经验 获得超4个赞
可以 watch 也可以 computed。
watch 的话需要 deep watch:
watch: {
list: {
deep: true,
handler( newList, oldList){
const changedIndex = newList.findIndex((item, index)=> {
oldList[index] !== item // 这里判断不严谨,你自己写判断方法
})
// changedIndex 就是发生改变的位置
}
}
}
computed 需要计算出你需要监听的那一项,然后再 watch 它,适合你明确知道自己想监听第几项的情况,比上边的性能好一点,毕竟监听的少。
添加回答
举报
