码迷,mamicode.com
首页 > 其他好文 > 详细

计算属性和侦听器

时间:2019-05-07 22:48:07      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:count   函数   改变   data   his   new   代码   root   fun   

计算属性:是一个属性的值发生改变时根据已有的属性计算出来的结果

侦听属性:根据属性值或计算属性发生改变后在侦听函数中写相应的逻辑代码

new Vue({

  el:"#root",

  data:{

    firstName:‘‘,

    lastName:‘‘,

    count:0

  },

  computed:{//当属性值发生改变时 fullName跟着改变

    fullName:function(){

      return this.firstName+" "+this.lastName

    }

  },

  watch:{//当fullName发生改变时 执行函数中的代码

    fullName:function(){
      this.count++
    }

  }

})

计算属性和侦听器

标签:count   函数   改变   data   his   new   代码   root   fun   

原文地址:https://www.cnblogs.com/sunhuinaxixi/p/10828670.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!