خرید بک لینک

Vote count: 0

I'm currently developing a webapp in Vuejs. I created a Mixin that I can access globally which handles any request to my api:

export default {

  data() {
    return {
      apiURL: 'http://example.com/api',
      timeout: 10000,
    };
  },

  methods: {

    callAPI(method, url, body) {
      this.$http({
        url: this.apiURL + url,
        method,
        body,
        timeout: this.timeout,
      })
      .then((response) =>
        response,
      (response) => {
        if (response.data.error) {
            this.error = response.data.error;
        } else {
          this.error = 'We can't coect to the server. Please try again in a few minutes.';
        }
        return response;
      });
      // return 'test';
    },

  },

};

Now, in some of my components I call the api function:

const api_response = this.callAPI('POST', '/auth', credentials);
alert (api_response);

It works fine, but one thing doesn't work as expected. I expect my api_response constant to have the value of response but it is always undefined. So every time I got this alert with undefined. How is that possible? When I uncomment the return 'test' line it works: I got an alert with test, but it doesn't seem to work within the this.$http part...

asked 45 secs ago

برچسب: how to return to sender,how to return games on steam,how to return to amazon,how to return a package,how to return a kindle book,how to return on ebay,how to return a groupon,how to return comcast equipment,how to return to windows 7,how to return a book on audible, نویسنده: استخدام کار تاريخ: شنبه 20 شهريور 1395 ساعت: 10:41

صفحه بندی