Watcher with the deep option code example
Example 1: vue deep watch
watch: {
colors: {
handler(newValue){
console.log('colors changed', newValue)
}, deep: true
}
}
Example 2: using the watch method to monitor route updates in vue
export default {
name: 'MovieData',
props: {
movie: {
type: String,
required: true,
}
},
data() {
return {
movieData: {},
}
},
watch: {
// Whenever the movie prop changes, fetch new data
movie(movie) {
// Fetch data about the movie
fetch(`/${movie}`).then((data) => {
this.movieData = data;
});
}
}
}