undefinedfix
Sign in

vuex unknown action type

joko edited in Sat, 10 Sep 2022

clipboard.png

clipboard.png

clipboard.png

clipboard.png

I have removed the namespace from the index, which is easy to use, but I don't know the specific reason

Is it like this or not

2 Replies
Kyle
commented on Sat, 10 Sep 2022

If you add a namespace, you can try. / GetMessage is like adding a package path to an action after subcontracting

const store = new Vuex.Store({
  modules: {
    account: {
      namespaced: true,

      // 模块内容(module assets)
      state: { ... }, // 模块内的状态已经是嵌套的了,使用 `namespaced` 属性不会对其产生影响
      getters: {
        isAdmin () { ... } // -> getters['account/isAdmin']
      },
      actions: {
        login () { ... } // -> dispatch('account/login')
      },
      mutations: {
        login () { ... } // -> commit('account/login')
      },

      // 嵌套模块
      modules: {
        // 继承父模块的命名空间
        myPage: {
          state: { ... },
          getters: {
            profile () { ... } // -> getters['account/profile']
          }
        },

        // 进一步嵌套命名空间
        posts: {
          namespaced: true,

          state: { ... },
          getters: {
            popular () { ... } // -> getters['account/posts/popular']
          }
        }
      }
    }
  }
})

Add a namespace, there is a nested namespace, a level of no need to add a namespace

Amer
commented on Sat, 10 Sep 2022

The first parameter of namespace mode mapactions needs to pass the module name of the module

Here is an example:

export default {
    methods: {
        ...mapActions('moduleKey', ['foo', 'bar'])
    }
}

The value of modulekey is the key of the corresponding object when you define modules, such as Foo and bar below

const store = new Vuex.Store({
    modules: {
        foo: moduleFoo,
        bar: moduleBar
    }
})

Refer to official documents