首页 > 其他 > 详细

vue学习笔记21 watch

时间:2020-05-05 00:39:16      阅读:80      评论:0      收藏:0      [点我收藏+]

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 = ‘棉衣‘
     }
   }
 },

vue学习笔记21 watch

原文:https://www.cnblogs.com/laohange/p/12828948.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!