Vue 计算属性

计算属性适用于逻辑复杂时使用,依赖于其他值的变化而变化,当计算属性中的值不发生变化时该计算属性仍然是上一次变化后缓存下来的值。

计算属性与监听器不同的是,监听器适用于当某个数据源发生变化时做其他某种操作,能够得到该数据源变化前后的值。

计算属性方法:


computed: {
getInfo() {
if (this.sitId!=""&& this.sitId!=undefined){
this.loading = true;
this.getData(sitId);
}
return sitId;
},
  className(){
    return this.number1+this.number2
  } 
},

使用计算属性

 <div class="loginCms-top">
        <p>{{className}}</p>
        <button @click="getInfo"></button> 
  </div>    
原文地址:https://www.cnblogs.com/xibaomeng/p/13713697.html