我有一个Vuexstore ,状态如下:
state: {
authed: false,
id: false
}
在一个组件中,我想观察authed
状态的变化,并向服务器发送一个AJAX调用.它需要在不同的组件中完成.
我试着使用store.watch()
,但当id
或authed
发生变化时就会触发.我还注意到,它与vm.$watch
的不同之处在于不能指定属性.当我try 这样做时:
store.watch('authed', function(newValue, oldValue){
//some code
});
我犯了这个错误:
[vuex] store.watch only accepts a function.
感谢您的帮助!