Reputation: 1482
I want to call a method which is not async whenever the state changes.
From what I understand, computed properties are used to return a value by doing some operations on state, and not to call a method. And watchers are used for async calling async functions generally.
I am new to Vue and think I am missing something basic here.
How can I call a method upon changing state? Can it be done using watchers? Would it be good practice?
Upvotes: 0
Views: 2090
Reputation: 4657
As Vuejs guide says:
While computed properties are more appropriate in most cases, there are times when a custom watcher is necessary. That’s why Vue provides a more generic way to react to data changes through the watch option. This is most useful when you want to perform asynchronous or expensive operations in response to changing data.
So you can call a method inside a watcher, even if it doesn't contain asynchronous operations. There's nothing wrong.
Upvotes: 1