每个计算属性都有一个getter和setter,完整的computed属性如下:
computed: {
isShowOverview: {
get () {
return this.$store.state.app.isShowOverview;
},
set (val) {
this.$store.commit("setIsShowOverview", val);
}
},
}
应为我们通常只用get来读取数据,所以会缩写成如下:
computed: {
getHeight () {
return this.isShowOverview ? document.body.clientHeight - 272 : document.body.clientHeight - 139;
},
}
但是get只能读取数据,不能在get中修改数据,不是双向绑定的,所以要修改时,需要增加set,在set里面写修改数据的操作。