store.js 646 B

123456789101112131415161718192021222324
  1. // 1. 导入 Vue 和 Vuex
  2. import Vue from 'vue'
  3. import Vuex from 'vuex'
  4. // 导入用户的 vuex 模块
  5. import moduleUser from './user.js'
  6. // 2. 将 Vuex 安装为 Vue 的插件
  7. Vue.use(Vuex)
  8. // 3. 创建 Store 的实例对象
  9. const store = new Vuex.Store({
  10. // TODO:挂载 store 模块
  11. modules: {
  12. // 2. 挂载购物车的 vuex 模块,模块内成员的访问路径被调整为 m_cart,例如:
  13. // 购物车模块中 cart 数组的访问路径是 m_cart/cart
  14. // m_cart: moduleCart,
  15. // 挂载用户的 vuex 模块,访问路径为 m_user
  16. m_user: moduleUser,
  17. },
  18. })
  19. // 4. 向外共享 Store 的实例对象
  20. export default store