关于listShow计算属性
来源:17-24 购物车详情页实现(4)

梦海千里渡
2018-03-26
最新的vue计算属性中的get和set搞得晕晕乎乎的,不太理解,尤其是放到控制购物车列表展示和隐藏中,一直搞不好,最后通过watch监听实现了,但是还是想请教一下老师,如果使用计算属性的话,这一块应该怎么写。在set中初始化scroll吗?试过在set中初始化,但是一直不成功。
totalCount: function () { if (!this.totalCount) { this.fold = false; } if (!this.fold) { this.$nextTick(() => { if (!this.scroll) { this.scroll = new BScroll(this.$refs.listContent, { click: true }); } else { this.scroll.refresh(); } }); } }, fold: function () { if (!this.totalCount) { this.fold = false; } }
最终我是通过 this.fold 实现的 v-show , 一开始的fold值设置为了false,如果这一块使用计算属性的话,应该怎么书写呢
写回答
1回答
-
其实用 watch 实现是合理的,新版 vue 的建议是不要在计算属性里去修改 data ,因为可能产生副作用。
212018-03-26
相似问题