vue中computed

152 阅读1分钟

1.computed

  1. complate有set和get方法,但是一般不用set方法,因此complate属性是只读的
//原始写法
computed:{
    total:{
    set:function(){
    }
    get:function(){
        return a+b
    }
}

//目前简写
computed:{
    total:function(){
       return a+b
     }
   }

2. 与methods区别

computed是有缓存的 如果多次使用,只调用一次

methods 没有缓存 如果多次使用,就会多次调用