Nuxt.js中的"$axios"的类型是什么?
P粉633309801
P粉633309801 2024-03-26 11:40:48
[Vue.js讨论组]

夏季

现在我实现了用于 API 连接的 RepositoryFactory 模式。

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

repository.ts中,我编写了$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)
}

但它显示错误消息 Binding 元素 '$axios' 隐式具有 'any' type.ts(7031)

我想知道 $axios 的正确类型是什么

我尝试过的

{ $axios } :any 可以解决它,但我想知道“$axios”的确切类型。

P粉633309801
P粉633309801

全部回复(1)
P粉039633152

您是否在 tsconfig.json 文件中添加了 @nuxt/types 和 @nuxtjs/axios ? 如果需要更多信息,可以查看:https://axios.nuxtjs.org/setup

{
  "compilerOptions": {
    "types": [
      "@nuxt/types",
      "@nuxtjs/axios"
    ]
  }
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号