问题遇到的现象和发生背景
像在methods中我们访问data中的属性,需要加this。那么,为什么在watch中访问其它对象中的属性不需要加this呢
问题相关代码,请勿粘贴截图
```javascript
<script>
Vue.config.productionTip = false
var vm = new Vue({
el: '#app',
data: {
isHot:true
},
methods: {
info(){
this.isHot = !this.isHot;
}
},
computed:{
weather(){
return (this.isHot? '炎热' : '凉爽');
}
},
//监视watch
watch:{
weather:{
immediate:true,//初始化时让handler调用一次(默认值:false)
//handler什么时候调用?当在weather发生改变时
handler(newValue,oldValue){
console.log('weather被改变了',newValue,oldValue);
}
}
}
})
</script>