计算属性和侦听器

mac2022-06-30  100

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

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

new Vue({

  el:"#root",

  data:{

    firstName:'',

    lastName:'',

    count:0

  },

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

    fullName:function(){

      return this.firstName+" "+this.lastName

    }

  },

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

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

  }

})

转载于:https://www.cnblogs.com/sunhuinaxixi/p/10828670.html

相关资源:详解vue 计算属性与方法跟侦听器区别(面试考点)
最新回复(0)