Sometimes, we want to watch for prop changes with the Vue.js Composition API.
In this article, we’ll look at how to watch for prop changes with the Vue.js Composition API.
How to watch for prop changes with the Vue.js Composition API?
To watch for prop changes with the Vue.js Composition API, we can call the watch
function.
For instance, we write
watch(
() => props.selected,
(selection, prevSelection) => {
/* ... */
}
);
to call watch
to watch the value of the selected
prop.
And then we can get the current value of selected
from selection
and the previous value of it from prevSelection
.
Conclusion
To watch for prop changes with the Vue.js Composition API, we can call the watch
function.