Vue tips
5 tips · newest first
Atomic Vue 3 tips covering the Composition API, reactivity gotchas, SSR safety, and the newest 3.5 APIs — each one a snippet you can apply in minutes.
Replace modelValue/update boilerplate with defineModel() for v-model
VUEdefineModel() returns a writable ref wired to the parent's v-model, collapsing the modelValue prop plus update:modelVal…
Cancel stale async work in watchers with onWatcherCleanup()
VUERegistered inside the watcher callback, onWatcherCleanup runs before the next invocation and on stop. It removes the ma…
Destructure props with native defaults in Vue 3.5, but pass a getter to watch
VUEStabilized in 3.5: destructured variables from defineProps compile to props.count on access, so they stay reactive and…
Generate hydration-safe unique IDs with useId() for accessibility
VUEuseId() produces IDs that are stable and identical across server render and client hydration, so label/for and aria-des…
Use useTemplateRef() for typed template refs instead of string-matched refs
VUEVue 3.5 resolves template refs by key at runtime, so the type is inferred and you drop the ref(null) declaration that h…