Watching for changes in components using watch
In the previous section, we learned how to load our data dynamically by triggering an API request during the component rendering cycle. In this section, we will see another aspect of asynchronous data loading by describing how to handle API requests, triggered as a side effect when watching for data changes.
As we learned in Chapter 5, computed properties are a great asset to watch other properties and internal data to create new variables, but they are not handy when we need to trigger a side effect, such as a DOM change or an API call.
This is where a Vue.js feature called watch
comes to the rescue. watch
, just like computed
, allows you to listen to any changes that occur to properties, reactive data, or another computed property, but it also provides you the ability to trigger a callback when data changes.
watch is just for edge cases, not everyday use
If you find yourself using watch
often during your development, it means...