我想通过在 Vue 组件中观察 Vuex 状态值来检测它的变化。我目前正在使用 Vue 3 和组合 API。我尝试过以下方法:
setup(props) {
const store = useStore();
watch(store.getters.myvalue, function() {
console.log('value changes detected');
});
return {
myvalue: computed(() => store.getters.myvalue)
}
},
Run Code Online (Sandbox Code Playgroud)
但改变console.log()时不会被调用。myvalue