如果存储中的数据发生变化,如何调用组件函数
How to call a component function if a data changes in store
我想在变量状态改变时触发一个方法(serviceSelected)。我正在尝试使用计算但它不起作用。我的变量在 vuex 商店中,它有一个 getter 作为 getServiceSelected
computed: {
...mapGetters(["getServiceSelected"]),
serviceChanged() {
this.serviceSelected(this.getServiceSelected);
return this.getServiceSelected
}
}
改用watch
er
computed: {
...mapGetters(["getServiceSelected"])
},
watch: {
getServiceSelected(newValue, oldValue) {
// do something
this.serviceSelected(newValue);
}
}
我想在变量状态改变时触发一个方法(serviceSelected)。我正在尝试使用计算但它不起作用。我的变量在 vuex 商店中,它有一个 getter 作为 getServiceSelected
computed: {
...mapGetters(["getServiceSelected"]),
serviceChanged() {
this.serviceSelected(this.getServiceSelected);
return this.getServiceSelected
}
}
改用watch
er
computed: {
...mapGetters(["getServiceSelected"])
},
watch: {
getServiceSelected(newValue, oldValue) {
// do something
this.serviceSelected(newValue);
}
}