vuex分割模块commit失败

inner.js

export default inner = {
  state: {
    acDeviceId: null
  },
  mutations: {
    setAcDeviceId(state, acDeviceId) {
      state.acDeviceId = acDeviceId
    }
  },
  getters: {
    getAcId: state => state.acDeviceId
  }
}

out.js

import inner from 'inner.js'
export default new Vuex.Store({
  state: {
    
  },
  mutations: {
    
  },
  actions: {

  },
  modules: {
    inner
  }
})

上面的代码是全局注册的,然后在其他组件中this.$store.commit('setAcDeviceId', 10),结果看到acDeviceId仍然为null,为什么呢?我看到项目其他地方也是这样写的都没问题啊

阅读 4.8k
3 个回答
export default new Vuex.Store({
modules: {
inner
}
})

this.$store.inner.commit('setAcDeviced', 10)?

把module导出语句改成

export default {
  state: {
    acDeviceId: null
  },
  mutations: {
    setAcDeviceId(state, acDeviceId) {
      state.acDeviceId = acDeviceId
    }
  },
  getters: {
    getAcId: state => state.acDeviceId
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进