Vue.js 要在Vuejs中的父组件之后运行的子组件上使用哪个生命周期挂钩?
在父级上,我运行以下命令:Vue.js 要在Vuejs中的父组件之后运行的子组件上使用哪个生命周期挂钩?,vue.js,vue-component,vuex,Vue.js,Vue Component,Vuex,在父级上,我运行以下命令: mounted(){ this.$store.dispatch('fetchNotesAction') }, components: { ChildComponent } 这样,Vuex存储区就充满了数据 因此,我假设,当子组件运行时,存储区已经满了 在ChildComponent中,我正在尝试这个 mounted(){ console.log(this.$store.getters.getNotes) }, 如果我在父级中记录了完全
mounted(){
this.$store.dispatch('fetchNotesAction')
},
components: { ChildComponent }
这样,Vuex存储区就充满了数据
因此,我假设,当子组件运行时,存储区已经满了
在ChildComponent
中,我正在尝试这个
mounted(){
console.log(this.$store.getters.getNotes)
},
如果我在父级中记录了完全相同的代码,则在分派之后,它将显示数据。因此,这些行后面的代码(连接)工作正常,只是我假设不需要再次运行fetch(从fetchNotesAction
)是否正确
我尝试了创建
而不是挂载
,同样的最佳做法是使用一个返回状态getter的计算属性,然后使用watch属性观察子组件中的更改:
computed:{
notes(){
return this.$store.getters.getNotes;
}
},
watch:{
notes(newval,oldVal)'
console.log(newval)
}
}