Vue · VUE0034
Derive state with computed() instead of a watcher
Finds watchers whose only effect is assigning a value derived from their sources to a local ref.
vue/reactivity/prefer-computed-over-watch-assignsrc/rule-packs/vue/rules/vue/prefer-computed-over-watch-assign.ts Upstream docs Run this rule
pnpm vite-doctor . --framework vue --extends auto,vue/strict --rules vue/reactivity/prefer-computed-over-watch-assign
Why it matters
A ref fed by a watcher is a second copy of derived state. A watch() without immediate does not run until a source changes, and Vue skips it entirely during server rendering, so the ref keeps its initial value until then. Other watchers write the ref in a later flush, so code that reads it right after changing a source sees the old value. computed() derives the value on read, caches it, and cannot drift from its sources.
Recommended fix
Replace the ref and the watcher with a computed(). This Rule is in the strict preset: a non-immediate watcher also skips its first run on the client, so server and client render the same initial value and the pattern is a design choice, not a hydration defect.
Useful links
Example
Derive state with computed()
Before
<script setup lang="ts">
const count = ref(1)
const doubled = ref(0)
watch(count, (value) => {
doubled.value = value * 2
})
</script>
After
<script setup lang="ts">
const count = ref(1)
const doubled = computed(() => count.value * 2)
</script>