Reputation: 1482
I'm using below code to watch for the change in Vuex state. The store file lies in the same directory. However, it doesn't seem to work. How do I watch for state change in vuex properly?
import store from './index'
store.watch(
(store) => store.state.base_url,
() => {
console.log('Watcher works')
}
)
Upvotes: 2
Views: 4513
Reputation: 34306
Are you sure you're just not using watch
correctly? According to the docs, the watch function receives the store's state as the first argument, so it should be:
store.watch(
state => state.base_url,
() => console.log('Watcher works')
)
Upvotes: 3