最新的vue计算属性中的get和set搞得晕晕乎乎的,不太理解,尤其是放到控制购物车列表展示和隐藏中,一直搞不好,最后通过watch监听实现了,但是还是想请教一下老师,如果使用计算属性的话,这一块应该怎么写。在set中初始化scroll吗?试过在set中初始化,但是一直不成功。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 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,如果这一块使用计算属性的话,应该怎么书写呢
掌握Vue1.0到2.0再到2.5最全版本应用与迭代,打造极致流畅的WebApp
了解课程