gpt4 book ai didi

javascript - 如何在Vuejs中查看同一数组中的不同键

转载 作者:行者123 更新时间:2023-12-01 00:37:03 26 4
gpt4 key购买 nike

我有如下代码。

data():{
coor: [
{ "name": '',
"shoes": '' },
{ "name": '',
"shoes": '' }
]

watch:{
coor: {
handler(){
console.log('changed')
}
,deep: true
}
}

在这种情况下,无论 coor 中的哪个值发生变化, watch 都会起作用。
但我的目标是我想将案例除以二,如下所示。

watch:{
coor.name: {
handler(){
console.log('The name is changed')
}
,deep: true
},
coor.shoes: {
handler(){
console.log('The shoes are changed')
}
,deep: true
}
}

但是效果不太好。我怎么解决这个问题?非常感谢您的阅读。

最佳答案

创建您想要观看的项目的计算属性,然后观看它。

computed {
filteredAny(){
return this.coor;
// you can also use map here and combine values to create a key.
// return this.coor.map(it=>it.shoes+':'+it.name)
},
filteredShoes(){
return this.coor.map(it=>it.shoes);
},
filteredName(){
return this.coor.map(it=>it.name);
}

}

watch {
// deep not needed.
filteredShoes(){
console.log('The shoes are changed');
}

}

关于javascript - 如何在Vuejs中查看同一数组中的不同键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58039474/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com