简体   繁体   English

Vue JS /超级代理-TypeError:fn不是函数

[英]Vue JS/ superagent - TypeError: fn is not a function

I'm using super agent for HTTP request and I'm trying to use superagent-intercept to catch HTTP requests in order to manage errors and necessary redirections. 我正在对HTTP请求使用超级代理,并且试图使用superagent-intercept来捕获HTTP请求,以便管理错误和必要的重定向。

When a componant is mounted I call an action from Vuex : 挂载组件时,我从Vuex调用一个动作:

GLOBAL_DATA({commit, state}) {
    forms_store.get(null,  (result) => {
        commit('SET_FORMS', result)
    });
}

Which call : 哪个电话:

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");
    }
  });
};

Considering : 考虑:

interceptor.auth = require('superagent-intercept')((error, results) => {
        // Error handling .. 
});

But I have an error in GLOBAL_DATA : 但是我在GLOBAL_DATA中有一个错误:

TypeError: fn is not a function TypeError:fn不是函数

I think something is overridden at some point but I can't figure out how to fix it. 我认为某些时候有些东西被覆盖了,但是我不知道该如何解决。

Edit : 编辑:

I changed the syntax of the first function but I still have the same error : 我更改了第一个函数的语法,但仍然有相同的错误:

GLOBAL_DATA : (context) => {
    forms_store.get(null,  (result) => {
        context.commit('SET_FORMS', result)
});

Define the action like this: 定义这样的动作:

GLOBAL_DATA: (commit, state) => {
    forms_store.get(null,  (result) => {
        commit('SET_FORMS', result)
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM