Bruno Francisco
Bruno Francisco

Reputation: 4220

Use $axios in a module in Nuxt

I would like to be able the same axios instance used in the auth module (https://auth.nuxtjs.org/) in a javascript module where I make my API calls

I have the following

const BASE_URL = 'job';

export default {
  getJobs(params?: Filter) {
    return axios.get(BASE_URL, { params });
  },
  getJob(slug: string, params?: Filter) {
    return axios.get(`${BASE_URL}/${slug}`, { params });
  }
}

I would like to be able to use the same $axios instance inside of this js module. Something like:

const BASE_URL = 'job';

export default {
  getJobs(params?: Filter) {
    return this.$axios.get(BASE_URL, { params });
  },
  getJob(slug: string, params?: Filter) {
    return this.$axios.get(`${BASE_URL}/${slug}`, { params });
  }
}

Is this possible?

Upvotes: 2

Views: 722

Answers (1)

ponnex
ponnex

Reputation: 848

Yes it is possible to get axios instance using this.$axios in Nuxt.js

enter image description here

Upvotes: 1

Related Questions