Reputation: 516
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.
Upvotes: 0
Views: 567
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