ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
1.定义 ``` export const state = ()=>({ typeList : [] }) export const mutations = { SET_TYPE_LIST(state,typeList){ state.typeList = typeList } } export const actions = { UPDATE_TYPE_LIST({commit,state},typeList){ commit('SET_TYPE_LIST',typeList) } } export const getters = { getTypeList(state){ return state.typeList } } ``` 2.使用 ``` // 调用actions 异步请求 this.$store.dispatch('UPDATE_TYPE_LIST',[]) // 调用mutations this.$store.commit('SET_TYPE_LIST',[]) ``` 辅助函数 ``` import {mapActions,mapGetters,mapState,mapMutations} from 'vuex' methods:{ getTypeList(){ this.UPDATE_TYPE_LIST([]) this.SET_TYPE_LIST([]) }, ...mapActions('user',['UPDATE_TYPE_LIST']) ...mapMutations('user',['SET_TYPE_LIST']) }, // 计算属性 computed:{ ..mapGetters('模块名称,根模块可以不传',['getTypeList']) ..mapState('模块名称,根模块可以不传',['typeList ']) } ```