javascript / beginner
Snippet
Reacting to Changes: watch
The watch function allows you to perform side effects (like data fetching or logging) whenever a specific reactive state changes.
snippet.js
1
2
3
4
5
6
import { ref, watch } from 'vue';const query = ref('');watch(query, (newValue) => {console.log('New search term:', newValue);});
vue
Breakdown
1
watch(query, (newValue) => { ... });
Instructs Vue to monitor the 'query' variable for any updates.
2
newValue
The first argument of the callback contains the most recent value of the source.