请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

watch侦听器

watch(() => error.value.status, () => {
      const { status, message } = error.value
      if (status && message) {
        createMessage(message, 'error')
      }
    })

watch函数中第一个参数为什么不能直接写error.value.status,而是要写一个函数返回error.value.status

正在回答

1回答

同学你好 用了 ts 很好解释,watch 的第一个参数希望十个响应式对象或者是getter fucntion,

export declare type WatchSource<T = any> = Ref<T> | ComputedRef<T> | (() => T)

这样才能能在对应的改变的时候作出对应的操作。

如果不用 getter function,error.value.status 这个东西就是一个普通的 js 值(这里是布尔),是无法监听变化的。

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号