Answer the question
In order to leave comments, you need to log in
Nuxt why axios not working?
Hello! I decided to add the Axios Module to nuxt. I did everything according to the instructions:
1) Installed npm install @nuxtjs/axios
2) Added a module to nuxt.config.js
modules: [
'@nuxtjs/axios',
],
async asyncData({ $axios }) {
const ip = await $axios.$get('https://jsonplaceholder.typicode.com/todos/1')
return { ip }
},
ERROR Cannot read property '$get' of undefined 16:18:09
at asyncData (index.vue:49:0)
at promisify (.nuxt/utils.js:262:0)
at server.js:1455:82
at Array.map (<anonymous>)
at module.exports../.nuxt/server.js.__webpack_exports__.default (.nuxt/server.
js:222:0)
Answer the question
In order to leave comments, you need to log in
asyncData accepts a context, see what is in it and look for axios
asyncData(ctx) {
console.log(ctx)
}
async asyncData({app}) {
const ip = await app.$axios.$get('https://jsonplaceholder.typicode.com/todos/1')
return { ip }
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question