I recently integrated axios into my nuxt.js application. Here is a snippet from my configuration file:
Configuration File: nuxt.config.js
modules: [
'@nuxtjs/vuetify',
'@nuxtjs/axios',
],
axios: {
// proxyHeaders: false
}
Below is a working example of my code:
export default {
data() {
return {
ip: ''
}
},
async asyncData({ $axios }) {
const ip = await $axios.$get('http://icanhazip.com')
return { ip }
}
}
However, the code snippet below is not functioning as expected:
export default {
data() {
return {
ip: ''
}
},
methods: {
async asyncData() {
const ip = await this.$axios.$get('http://icanhazip.com')
this.ip = ip
}
}
}
I am facing an issue with the axios request inside the methods
section. Any insights on why this might be happening?