背景:2个组件:home和search,将store仓库拆分成2个小仓库,home和search两个小仓库用于管理自己模块的数据
store文件夹下新建2个文件夹:home和search
home下index.js
//home模块的小仓库 const state = { a:1 }; const mutations = {}; const actions = {}; const getters = {}; export default{ state, mutations, actions, getters }
search下index.js
//search模块的小仓库 const state = { b:2 }; const mutations = {}; const actions = {}; const getters = {}; export default{ state, mutations, actions, getters }
store下index.js
import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex); //引入小仓库 import home from './home' import search from './search' //对外暴露Store类的一个实例 export default new Vuex.Store({ //实现Vuex仓库模块式开发存储数据 modules:{ home, search } })
标签:search,const,仓库,开发,模块,home,Vuex From: https://www.cnblogs.com/ixtao/p/17234156.html