Last active
March 24, 2025 12:41
-
-
Save Kcko/b7199eac8eeb75bbb3dd7dff1569fa5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1) cleanup when watch is ended | |
import { watch, onWatcherCleanup } from 'vue' | |
watch(id, (newId) => { | |
const { response, cancel } = doAsyncWork(newId) | |
// `cancel` is called if `id` changes or the component unmounts | |
onWatcherCleanup(cancel) | |
}) | |
// 2) better watch with desctruct | |
const { pause, resume, stop } = watch(source, (newVal, oldVal) => { | |
// Watch logic | |
}); | |
// Pause watching | |
pause(); | |
// Resume watching | |
resume(); | |
// 3 watch logic, not only true/false ... | |
watch(reactiveObject, (newVal, oldVal) => { | |
// Watch logic | |
}, { deep: 2 }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment