Vue · VUE0050
Watch a reactive property through a getter
Finds direct property reads passed as a `watch()` source or as an entry in a source array, when the property is known to hold a primitive. Doctor looks at `defineProps()` declarations and local `const` objects initialized with `reactive()` and a literal. It leaves refs, getter functions, intentional deep watches of reactive objects, and unresolved values alone. Destructured props are covered by `vue/reactivity/defineprops-watch-getter`.
vue/watch/no-property-read-sourcesrc/rule-packs/vue/rules/vue/no-property-read-watch-source.ts Upstream docs Run this rule
pnpm vite-doctor . --framework vue --rules vue/watch/no-property-read-source
Why it matters
watch(props.userId, cb) evaluates props.userId once and passes its current value. A primitive is not a valid watch source, so Vue cannot subscribe to changes to the property. A getter lets Vue track the property read and run the callback when the value changes.
Recommended fix
Pass a getter, watch(()` => props.userId, cb)`. In a source array, wrap only the primitive property read: watch(()` => props.userId, otherSource, cb)`.
Useful links
Example
Watch a prop through a getter
Before
<script setup lang="ts">
import { watch } from 'vue'
const props = defineProps<{ userId: string }>()
watch(props.userId, (id) => loadUser(id))
</script>
After
<script setup lang="ts">
import { watch } from 'vue'
const props = defineProps<{ userId: string }>()
watch(() => props.userId, (id) => loadUser(id))
</script>