Vue · Middle · Question 9 of 75

How do you make a watch callback also run right away with the current value?

watch(() => route.params.id, loadUser, { immediate: true });

Explanation

By default watch is lazy and fires only on changes. immediate runs it once on creation; { once: true } (3.4+) stops it after the first trigger.

Further reading

Problem with a question

Vue · Middle · question 9

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