【Vue】关于vuex中Store模块化

各个路由自己的仓库可以在其文件夹中新建名为xxxStore/xxxAbout.js

image

需要在各个模块内开启namespaced:true

// 登录页请求
const loginAbout = {
  namespaced: true,
  actions: {},
  mutations: {},
  status: {}
}
export default loginAbout

在大仓库store/index.js内引入,并模块化

import Vuex from 'vuex'
import Vue from 'vue'

import homeAbout from '../pages/Home/homeStore/homeAbout.js'
import searchAbout from '../pages/Search/searchStore/searchAbout.js'
import loginAbout from '../pages/Login/loginStore'
Vue.use(Vuex)

export default new Vuex.Store({
  modules: {
    homeAbout,
    searchAbout,
    loginAbout
  }
})

posted @ 2022-04-10 00:05  一个大不刘blog  阅读(165)  评论(0编辑  收藏  举报