What is the type of "$axios" in Nuxt.js?
P粉633309801
P粉633309801 2024-03-26 11:40:48
0
1
347

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粉633309801
P粉633309801

reply all(1)
P粉039633152

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"
    ]
  }
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!