computed 计算属性
data(){
return {
aa:1
}
},
computed:{
newData:function(){
return this.aa
},
},
watch:{
aa:function (newV,oldV) {
console.log(333)
}
},
computed用于处理复杂的逻辑运算(不支持异步,有缓存),主要和methods存储方法来进行区分, watch监听数据变化,其中可以监听的数据来源1.props,2.data 3.computed的数据 watch(支持异步)提供两个参数(newV,oldV)
get,set监听机制 如果数据发生变化 set重新设置值。computed性能更好是因为,只有数据发生变化才会执行
其中computed可以用来处理多对一的数据,是因为newData这个值会随着他的依赖值的变化而变化
watch可以处理一对多,因为aa是已经定义了的值,aa变化会触发里面的函数
watch深度监听
$route:{
handler:function(newV,oldV){
},
deep:true,
immediate:true
}