【发布时间】:2020-05-08 22:44:47
【问题描述】:
我正在更新以前开发人员的代码,但我一直在纠结为什么我不能这样做,因为代码返回了这个错误:
Uncaught (in promise) TypeError: failedCallback is not a function
这是我正在使用的函数:
export default {
get(callback, failedCallback) {
axios.get(`/admin/shops`)
.then(response => callback(response.data))
.catch(errors => failedCallback(errors))
}
}
然后像这样导入:
import getShop from '../api/shops'
并在我的全局路由器保护中这样使用
router.beforeEach((to, from, next) => {
if(to.name == null){
getShop.get(
data => {
if(data.setup) {
debugger;
this.$store.dispatch('getBackground', false); #this is the line that causes the error!
next({ name: 'customers_table'});
}
else {
next({ name: 'plans'})
}
});
}
else {
next();
}
})
当我添加下面的行时,我得到了 TypeError
this.$store.dispatch('getBackground', false);
不知道为什么会出现该错误或如何解决?
编辑:
这是我的getBackground 操作
getBackground: ({ commit }, payload) => {
commit('changeBackground', payload);
}
【问题讨论】:
-
你能把错误信息也贴出来吗?
-
@helper 是的,它在顶部.. 这就是错误
-
您能发布 getBackground 操作的代码吗? (这就是引发异常的原因)
-
@helper 确定.. 我将它添加到 OP