Ricardo Albear
Ricardo Albear

Reputation: 516

Custom function in nuxt-axios

Is it possible to have a custom function in nuxt-axios

async fetchSomething({ commit }) {
    const response = await this.$axios.customGet(
      `/blabla`
    );

    await commit("setVideoData", response);
  }

And this customGet() can have their own baseUrl and custom headers

Edited to add extra information

This is what i add to plugins/axios.js as a try for the customGet() function

export default function({ $axios, store, redirect }) {
  $axios.customGet(body => {
    console.log("body from custom get", body);
  });
}

But is not working and i get this error.

enter image description here

Upvotes: 0

Views: 567

Answers (1)

mgarcia
mgarcia

Reputation: 6325

You are getting the TypeError error because you are calling the function customGet (that does not exist) instead of defining it.

Your plugins/axios.js should look like:

export default function({ $axios, store, redirect }) {
    $axios.customGet = body => {
        /* The logic for customGet goes here */
        console.log("body from custom get", body);
    };
}

Upvotes: 1

Related Questions