vue.js - vue updated 仅运行一次,并且在父元素中进行更改后不再运行
问题描述
我在 vue3 中遇到了一个奇怪的行为。
我像这样在父元素中设置提供。
应用程序.vue
data(){
return{
allData:[],
ingCollection:[],
selectedDish:[],
selectedIngred:[]
}
},
mounted(){
Promise.all([
d3.json('data.json'),
d3.json('ingredientsonly.json')
]).then((data)=>{
data[0].forEach((d)=>{
this.allData.push(d)
})
data[1].forEach((t,i)=>{
// for ingredient selection,
// later on, need to sort the ingredients by
// frequency of the ingredients in the data set
if(i<100){
this.ingCollection.push(t)
}
})
})
},
provide() {
return{
allData:this.allData,
ingCollection:this.ingCollection,
selectedDish:this.selectedDish,
receiveIngredients:this.receiveIngredients,
selectedIngred:this.selectedIngred
}
}
子元素 - sidePanel.vue
inject:['selectedIngred'],
updated(){
console.log('firstly updated')
console.log(this.selectedIngred)
}
当我在“selectedIngred”中进行更改时,它只运行一次 updated() 生命周期挂钩,updated() 不会在子元素中运行。
这是为什么?
谢谢
解决方案
推荐阅读
- eos - EOSIO - cleos 钱包创建命令抛出错误“无效的内容长度响应”
- ios - AVPlayer: delay when status is ReadyToPlay and first frame appearing
- python - Python新手在真实“地图”上操作地理数据
- java - 如何考虑多个空格的存在?爪哇
- python - BeautifulSoup,如何正确使用 decompose()
- ios - 自定义类数据未快速显示在表格视图中
- amazon-web-services - AWS AppSync 超过每个用户计数的最大终端节点数 10
- sql - 无法架构绑定 sql server 视图
- javascript - 如何使用 jQuery 检查 li 元素?
- typescript - tsc-watch 是否消耗 TSC_NONPOLLING_WATCHER?