watch Watchers (Options Style)

Last updated: 2026-10-22

watch Watchers (Options Style)

The watch option keys callbacks by the watched property name, supporting handler, deep, immediate and string method shorthand.

GroupOptions: State
KindOption
ScopeComponent
Vue Version3.0+
SSR SupportYes

📝 Syntax

export default {
  data() { return { keyword: "" } },
  watch: {
    keyword(newVal, oldVal) { /* ... */ },
    "user.name"(v) { /* quote nested paths */ }
  }
}

⚙️ Arguments

valueAn object keyed by data paths (quote dotted paths), valued by a function or { handler, deep, immediate }

Returns:No return; callbacks receive (newValue, oldValue)

▶ Example

Edit the code below and see the live result:

Output:

Typing logs 'old → new', for example 'a → ab'.

💡 Key Points

💡 Tip Lazy by default — add immediate: true to run at setup.
⚠️ Warning Quote nested paths or use deep: true, mindful of cost.
ℹ️ Note A string value reuses a method as the handler.
More case studies coming soon.

📚 Related Tutorials

❓ FAQ

Q Relation to the Composition API watch?
A Two spellings of one mechanism: keyed by name versus explicit source.
Q How to watch an array?
A Replacement triggers; in-place push needs deep: true or length watching.
Q Watch several at once?
A Use several keys, or watch([a, b]) in the Composition API.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏