遇到问题
在使用 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) } }}
回上一页
回下一页