您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

vuex无法提交子模块mutations

vuex无法提交子模块mutations

vuex模块化之后如何提交子模块的方法?

版本

  • vue3
  • vuex4.x
  • javascript

代码

user.js

export default createStore({
  state: () => ({
    username: 'nihao',
    password: ''
  }),
  mutations: {
    setUsername: (state, username) => {
      state.username = username
    }
  },
  actions: {
  },
  modules: {
  }
})

index.js

import user from './modules/user'
export default createStore({
  state: {
  },
  mutations: {
  },
  actions: {
  },
  getters: {
  },
  modules: {
    user: user
  }
})

调用的方法

const store = useStore()
store.commit('setUsername', 'xxx')
store.commit('user/setUsername', 'xxx')

无论是加了namespaced: true还是不加,上面的两句话都不行。

vuex 2022/2/7 16:57:14 有539人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶