首页 > 解决方案 > vuex 模块的 npm 包在调度后给出错误

问题描述

我刚刚制作了一个 npm 包作为我的 vuex 的模块。经过长时间的尝试,我终于可以安装它并将其与我的 vuex 混合使用。使用此链接 ,我控制台记录了我的商店,幸运的是,操作部分包含我的 npm 包。但是当我想发送它给我一个错误:(在我的应用程序中使用它,比如:

this.$store.dispatch('orderiomApiPackageAuth/auth')

发给我错误:

[vuex] unknown action type: orderiomApiPackageAuth/auth

在我的 module.js 中:

import axios from "axios";

const state ={
    restaurantInfo: {},
    imprint: null
};

const mutations = {
    setRestaurantInfo(state, restaurantInfo) {
        state.restaurantInfo = restaurantInfo
    },
    setImprint(state, imprint) {
        state.imprint = imprint
    }
};

const actions = { //some action here }
export default {
    namespaced: true,
    state,
    mutations,
    actions
};

在我的 index.js 包中:

import myModule from '/.module.js'

function install(Vue, options ={}) {
  if (!options.store) console.log('Please provide a store!!')
    
  options.store.registerModule('desiredName', myModule )
}

export default {
  install
}

并在我的 main.js 项目中使用它:

import myPackage from 'myPackage'
import store from './store'

Vue.use(myPackage, { store })

我 console.log(this.$store) 并且我意识到 action 部分包含我的模块。但我对派遣他们有疑问。

我从控制台拍了一张快照,在这里分享:

在此处输入图像描述 有什么帮助吗?:(

标签: vue.jsnpmvuexnpm-installvuex-modules

解决方案


推荐阅读