vuex的调用方法
整理vuex使用的两种方式
·
一、调用state数据
①$store.state.数据
②$store.state.模块名.数据
二、调用mutations方法
①方法名(){ this.$store.commit('定义方法名') }
②使用mapMutations辅助函数
import {mapMutations} from 'vuex'
methods:{...mapMutations(['定义方法名'])}
方法名(){ this.$store.commit('定义方法名') }
三、调用actions方法
①方法名(){this.$store.dispatch('定义方法名')}
②使用mapActions辅助函数
import {mapActions} from 'vuex'
methods:{...mapActions(['定义方法名'])}
方法名(){this.$store.dispatch('定义方法名')}
四、getters
定义:数据名:state=>state.模块名.数据
使用:①$store.getters.数据名
②使用mapGetters辅助函数
import {mapGetters} from 'vuex'
computed:{ ...mapGetters(['数据名'])}
更多推荐
已为社区贡献3条内容
所有评论(0)