|
在使用VUEX中使用到了mapGetters及mapActions.
1. mapGetters或mapActions的使用方法 调用其方法时,使用如下代码: computed:mapGetters(['count']) 如要要调用mapGetter或mapActions中的多个方法: computed:mapGetters(['count','id','username']) 如果想给getter属性换名字 computed:mapGetters({doneCount:'count'}) 2. mapGetters或mapActions使用原理 如以下代码: computed:mapGetters(['count']) 实际上等价于 computed: { count() { return this.$store.state.count } } mapGetters (): 返回的是一个对象,这个对象里存储的是对应的函数 3. computed如何还有其它的计算,那应该如何写 computed: { localComputed () { /* ... */ }, // 使用对象展开运算符将此对象混入到外部对象中 ...mapGetters({ // ... }) } 注:实现方法就是在方法前加三个点...mapGetter, 这三个点代表什么意思呢,它是es6的语法,代码是将此对象合并到,外部对象中。数组中也可以这样使用。关于对运算符的,详细介绍,可参考:http://bugshouji.com/sharetel/t341-1 参考:http://www.jb51.net/article/111589.htm https://segmentfault.com/q/1010000010347791 http://blog.csdn.net/qq_34629352/article/details/78155803 |
|
|