I create a watcher within the setup, this works:
watch(() => variableToWatch, (newVal,oldVal) => {
console.log(newVal,oldVal)
})
But this does not (no errors, just doesn’t seem to do anything):
const fnTest = (newVal,oldVal) => {
console.log(newVal,oldVal)
})
watch(() => variableToWatch, (newVal,oldVal) => fnTest)
Can we not use a function in the watcher callback?
To be fair, I’m still on Vue3, and use the https://github.com/vuejs/composition-api, but that shoulnd’t matter in this case.
>Solution :
Your const "is" the whole function.
So this should work:
const fnTest = (newVal,oldVal) => {
console.log(newVal,oldVal)
})
watch(() => variableToWatch, fnTest)