2

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')
  }
)
Shubham Chaudhary
  • 1,322
  • 2
  • 18
  • 38
  • is this what your trying to do? https://stackoverflow.com/questions/43270159/vuejs-2-how-to-watch-store-values-from-vuex – Chris Li Sep 10 '18 at 04:33

1 Answers1

3

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')
)
Decade Moon
  • 32,968
  • 8
  • 81
  • 101