分完模块以后 state 的数据在页面中可以使用 map 映射调用也可以是 原型 调用具体如下:
state 里的属性调用:
映射方法:
import { mapState } from 'vuex'
然后在 computed 里面去挂载 ...mapState(['模块名','属性名'])
在需要的地方直接用 this.模块名.属性名 直接调用即可
原型方法:
直接在需要的地方 this.$store.模块名.属性名 即可
mutations 里的方法调用:
映射方法:
import { mapMutations } from 'vuex'
然后在 methods 里面去挂载 ...mapMutations (['模块名/方法名'])
在需要的地方直接用 this.方法名(要传递的参数) 直接调用即可
原型方法:
直接在需要的地方 this.$store.commit('模块名/方法名',传递的数据) 即可
actions 里的方法调用:
映射方法:
import { mapActions } from 'vuex'
然后在 methods 里面去挂载 ...mapActions (['模块名/方法名'])
在需要的地方直接用 this.方法名(要传递的参数) 直接调用即可
原型方法:
直接在需要的地方 this.$store.dispatch('模块名/方法名',传递的数据) 即可
getters 里的方法调用:
映射方法:
import { mapGetters } from 'vuex'
然后在 computed 里面去挂载 ...mapGetters (['模块名/方法名'])
在需要的地方直接用 this.方法名(要传递的参数) 直接调用即可
原型方法:
直接在需要的地方 this.$store.getters ('模块名/方法名') 即可