你瞅啥呢

2024-08-20 Invalid watch source: A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types. ==》vue3的watch写法问题

我的watch写法:

watch(props.value, (val) => {
    content.value = val;
});

然后控制台抛出了一个警告:无效的watch源:watch源只能是getter/effect函数、ref、响应对象或这些类型的数组。

原因:watch写法不正确导致。

解决方案:

正确写法为:

watch(() => props.value, (val) => {
    content.value = val;
});

是的,我露了箭头函数。

posted @ 2024-08-20 17:34  叶乘风  阅读(1496)  评论(0)    收藏  举报