BeginnerCoder

Lesson 24 — watchEffect

Effects that track themselves

watchEffect(fn) runs fn immediately and records every reactive value fn reads. Whenever any of them changes, it runs fn again. Unlike watch, you do not list the sources — Vue discovers them automatically.

watchEffect(() => {
  document.title = cartCount.value + " items" // re-runs when cartCount changes
})

Why it matters: syncing to the page title, localStorage or a log stays correct without listing dependencies by hand.

Want it another way?
Task

Use watchEffect to log "count is" plus the value. Open the console: on load it shows count is 0, and each click adds count is 1, count is 2…

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with Vue.js Foundations

Ready for more? Optional paid resources that pick up where this lesson leaves off.

Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.