Core Concepts: State Watchers and Subscribers

Learn how to watch a Vuex state and react to any changes.

In some cases, a mutation in the state also causes some other kind of behavior. Think of logins. As soon as a user has logged in to the website, additional data, such as personalized feeds or dashboard data may need to autoload. In these cases, watching the state is an option.

What are watchers?

We can subscribe to any part of the state and execute any function as soon as the state changes. Such a function is called a watcher. We introduce watchers with the store.watch method of our Vuex store. The method takes two arguments—a getter that describes which property to observe and a callback that Vuex should execute. The callback itself takes the output of the getter as an argument.

Get hands-on with 1200+ tech skills courses.