//默认就是根store,不需要namespaced:true,访问的时候直接写根级别的key : this.$store.dispatch('example) export const state = () => ({ bannerConfig: {} }) export const mutations = { SET_BANNER_CONFIG(state, config) { state.bannerConfig = config } } export const actions = { // 只在服务端渲染时运行一次 async nuxtServerInit({ dispatch, commit }, { app, req }) { await dispatch('getBannerConfig'); }, async getBannerConfig({ commit }) { const {data: res} = await this.$api.config.getModuleConfigKey('banner') const {code, data} = res; if (code === 0 && data.banner) { commit('SET_BANNER_CONFIG', data.banner); } } } export const getters = { bannerConfig: (state) => state.bannerConfig }