[英]Vue JS/ superagent - TypeError: fn is not a function
我正在对HTTP请求使用超级代理,并且试图使用superagent-intercept来捕获HTTP请求,以便管理错误和必要的重定向。
挂载组件时,我从Vuex调用一个动作:
GLOBAL_DATA({commit, state}) {
forms_store.get(null, (result) => {
commit('SET_FORMS', result)
});
}
哪个电话:
forms.get = function(root, cb) {
request
.get(`${api}/forms/name/FORM`)
.use(interceptor.auth)
.use(nocache)
.withCredentials()
.set('Accept', 'application/json')
.end(function(err, res) {
if (res.body.status === 'success') {
cb(res.body.data.forms, root)
} else if (common.token(res)) {
common.cb(root);
} else {
console.log("error");
}
});
};
考虑:
interceptor.auth = require('superagent-intercept')((error, results) => {
// Error handling ..
});
但是我在GLOBAL_DATA中有一个错误:
TypeError:fn不是函数
我认为某些时候有些东西被覆盖了,但是我不知道该如何解决。
编辑:
我更改了第一个函数的语法,但仍然有相同的错误:
GLOBAL_DATA : (context) => {
forms_store.get(null, (result) => {
context.commit('SET_FORMS', result)
});
定义这样的动作:
GLOBAL_DATA: (commit, state) => {
forms_store.get(null, (result) => {
commit('SET_FORMS', result)
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.