问题
报错如下:
Invalid watch source: undefined A watch source can only be a
getter/effect function, a ref, a reactive object, or an array of these
types. at <Index onVnodeUnmounted=fn ref=Ref<
undefined > key=“/running-attention/safe/picture” > at <KeepAlive
key=1 include= [‘monitor’] >
分析
代码写法:
watch(props.visible, (newVal) => {
if (newVal) {
xxxx....
}
})
一开始以为是不能直接用这种简单数据类型,改成了对象,后面看了官方文档,发现是写错了
监听值要用函数返回 () => props.visible
正确写法:
watch(() => props.visible, (newVal) => {
if (newVal) {
xxxx....
}
})
如果你监听的是一个对象, 如:
```javascript
watch(props.formData, (newVal) => {
if (newVal) {
xxxx....
}
})
控制台不会报错,但是不会进入你的 (newVal) => {}函数中,可能半天都找不到问题