我正在尝试在我的项目中使用 vuex,但出现错误“[vuex] 未知操作类型”

I am trying to use vuex in my project , but there is an error "[vuex] unknown action type"

这是我使用vuex的代码。

我在google上搜索这个错误,有人回答说这是因为“namespaced:true”,所以我评论了这一行,但错误仍然存​​在。

此外,如果我直接使用测试,当我把它放在模块中时,所有东西都只是fine.But,它不起作用。

//src/store/index.js

import { createStore } from 'vuex'
import test from './modules/test'

export default createStore({
  modules: {
    test
  }
})
//src/store/modules/test.js

import { createStore } from 'vuex'

export default createStore({
  namespaced: true,
  state () {
    return {
      count: 0
    }
  },
  mutations: {
    increment (state) {
      state.count++
    }
  },
  actions: {
    action_increment ({ commit }) {
      commit('increment')
    }
  }
})

我的使用方式

methods: {
    test () {
      this.$store.dispatch('test/action_increment')
    }
  }

您不应为您的模块创建新商店。看这里https://vuex.vuejs.org/guide/modules.html