My setup is as follows:
<script setup lang="ts">
const props = defineProps({
count: {
type: Number,
default: 0
}
})
const { count } = toRefs(props)
watch(count, (newValue, oldValue) => {
console.log(newValue, oldValue);
})
</script>
The console log is never run.
If I on the other hand set { immediate: true }, it does run but only logs out the new value - old is always undefined.
What am I doing wrong here?
Thank you!
I had the same issue trying to add watchers on props in Composition API with script setup.
The solution proposed by Thomas in the question's comments solve the issue.