Vue · Middle · Question 56 of 75

How do you stop a watcher before the component unmounts?

const stop = watch(source, callback)
// later
stop()

Explanation

Watchers created synchronously in setup stop automatically on unmount. Watchers created asynchronously must be stopped manually to avoid leaks.

Further reading

Problem with a question

Vue · Middle · question 56

Test yourself

Take the Vue · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz