data:{
weather:25,
wear:'短袖'
}
实例属性写watch监控
构造器外部写法
app.$watch('xxx',function(){})
写在构造器里
watch:{
weather:function(nv,ov){
}
}
用computed实现 就不灵活了。例
computed:{
newWear:function(){
if(this.weather>=25){
return this.wear = 'T恤短袖'
}else if(this.weather<25 && this.weather>0){
return this.wear = '外套'
}else{
return this.wear = '棉衣'
}
}
},