vue中computed 和 watch的异同
computed 在数据未发生变化时,优先读取缓存。computed 计算属性只有在相关的数据发生变化时才会改变要计算的属性,当相关数据没有变化是,它会读取缓存。而不必想 motheds方法 和 watch 方法是的每次都去执行函数。 computed:{ fullName:{ //这里用了es6书写方法 set(){ alert("set"); }, get(){ alert("get"); return this.firstName + " " +this.lastName; }, } } watch 值变化,就需要去调用它相应的函数 文章来源: vue中computed 和 watch的异同