Vue.js [watch]: 物件属性如何用 watch

遇到问题

在使用 Vue 的 watch 的时候,一般都是用这样的

watch:{    text:{        handler(newValue){            console.log(newValue)        }    }}

这样就可以使用 watch 观察 text 这个变数。
但是如果想要观察这个物件的 title 的话就不知道怎么做

message:{    title:'',    container:'',    footer:'',}

解决方法

Vue 想要观察物件的话可以这样做
message:{    title:'',    container:'',    footer:'',}

只要在观察的变数上加入 '' "单引号"就可以了

watch:{    'message.title':{        handler(newValue){            console.log(newValue)        }    }}

回上一页
回下一页


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章