search

Home  >  Q&A  >  body text

What is the type of "$axios" in Nuxt.js?

summer

Now I implemented the RepositoryFactory pattern for API connection.

https://medium.com/canariasjs/vue-api-calls-in-a-smart-way-8d521812c322

In repository.ts I wrote $axios.

import testRepository from '~/api/testRepository'

export interface Repositories {
  hoge: testRepository 
}

export default function ({ $axios }, inject) { # <- error on $axios
  const hoge = new testRepository ($axios)
  const repositories: Repositories = {
    hoge
  }
  inject('repositories', repositories)
}

But it shows error message Binding element '$axios' implicitly has 'any' type.ts(7031).

I want to know what is the correct type of $axios

What I tried

{ $axios } :any can solve it, but I want to know the exact type of "$axios".

P粉633309801P粉633309801352 days ago478

reply all(1)I'll reply

  • P粉039633152

    P粉0396331522024-03-27 09:07:26

    Have you added @nuxt/types and @nuxtjs/axios in the tsconfig.json file? If you need more information, you can check out: https://axios.nuxtjs.org/setup

    {
      "compilerOptions": {
        "types": [
          "@nuxt/types",
          "@nuxtjs/axios"
        ]
      }
    }

    reply
    0
  • Cancelreply