nuxt-community / axios-module

Secure and easy axios integration for Nuxt 2
https://axios.nuxtjs.org
MIT License
1.19k stars 245 forks source link

TypeError: Cannot read property '$get' of undefined #484

Closed teckel12 closed 3 years ago

teckel12 commented 3 years ago

I'm missing something really basic and it's as if axios is not being loaded. I did the following:

  1. npm install --save @nuxtjs/axios which successfully installs nuxtjs/axios v5.13.1
  2. In nuxt.config.js I added:
    export default {
    modules: [
        '@nuxtjs/axios'
    ]
    }
  3. In a component I added the following method:
    export default {
    methods: {
        async test() {
            const ip = await this.$axios.$get('http://icanhazip.com')
            this.ip = ip
        },
    }
    }

When I call the test() method I get the title error as if axios can't be found. If I do a await this.$axios({ ... }) I get the following:

TypeError: _this.$axios is not a function

So sure enough, it can't find axios. Any idea what I missed? I seem to be following the install and setup from https://axios.nuxtjs.org/setup

pi0 commented 3 years ago

Hi @teckel12. It is hard to figure out the issue from the description above. If you can share project or provide a reproduction can help.