【问题标题】:Vue cant recognize srcvue 无法识别 src
【发布时间】:2021-05-20 09:51:14
【问题描述】:

我使用@vue/cli@4.5.11(Babel、TS

当我这样做时

npm 运行服务

它说

未找到这些依赖项:

  • ./src/store/user.ts 中的 src/config/GlobalConfig

我是这样导入的:

import { GlobalAxios } from 'src/config/GlobalConfig';

当我将其更改为 /src/config/GlobalConfig

我收到以下类型错误:

Cannot find module '/src/config/GlobalConfig' or its corresponding type declarations.

如何正确使用商店中的文件?

【问题讨论】:

    标签: typescript vue.js


    【解决方案1】:

    您应该使用相对路径(可能文件扩展名取决于项目配置)

    也许:

    import { GlobalAxios } from '../config/GlobalConfig'
    

    或者:

    import { GlobalAxios } from '../config/GlobalConfig.js' // .ts ?
    

    或者(如果配置了 webpack 别名):

    import { GlobalAxios } from '@/config/GlobalConfig.js' // .ts ?
    

    【讨论】:

      猜你喜欢
      • 2018-07-13
      • 2010-12-12
      • 1970-01-01
      • 2018-12-06
      • 2014-05-31
      • 2017-04-15
      • 2017-10-18
      • 2022-11-26
      • 2018-03-14
      相关资源
      最近更新 更多