3.0.0 vue: 2.4.2 -> 2.5.2 vue-router: 2.7.0 -> 3.0.1 (还有一些,但我认为它-6ren">
gpt4 book ai didi

vuejs2 - "Error: [vuex] actions should be function or object with "处理程序 "function but "actions.default "is {}"更新 Vue & Vuex 后

转载 作者:行者123 更新时间:2023-12-01 16:19:12 28 4
gpt4 key购买 nike

我对我的项目进行了以下 npm 包更新:

vuex: 2.3.1 -> 3.0.0
vue: 2.4.2 -> 2.5.2
vue-router: 2.7.0 -> 3.0.1

(还有一些,但我认为它们与这个问题无关)

现在我在启动网页时遇到此错误:

Error: [vuex] actions should be function or object with "handler" function but "actions.default" is {}

我不太确定为什么,我阅读了 Vuex 变更日志,语法似乎并没有真正改变,但由于某种原因我的代码崩溃了。

仔细检查这个问题后,我发现错误是由名为 vuex.esm.js 的文件中的失败断言产生的:

function assert (condition, msg) {
if (!condition) { throw new Error(("[vuex] " + msg)) }
}

代码在更新包之前工作正常,我可能在这里遗漏了一些东西。我很乐意提供任何可能有助于更好地理解问题的代码。

谢谢!

编辑:这是导致错误的调用堆栈: Call stack

最佳答案

我在单元测试中遇到了同样的错误。我只是在我的操作中添加了一个空的 handler 函数,然后它就开始工作了......

const state = { auth: { authenticated: false } };
const actions = { auth: { handler: () => {}, logout: () => sinon.stub() } };
let store;
beforeEach(() => {
store = new Vuex.Store({
state,
actions,
});
});

关于vuejs2 - "Error: [vuex] actions should be function or object with "处理程序 "function but "actions.default "is {}"更新 Vue & Vuex 后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46999322/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com