路径无法跳转的问题

KX / 2023-08-18 / 原文

路径无法跳转问题

image-20230818172418528

在 ts 文件中引入 .vue 文件时还出现以下报错

image-20230818172851090

报错原因:typescript 只能理解 .ts 文件,无法理解 .vue文件

解决方法:在项目根目录或 src 文件夹下创建一个后缀为 .d.ts 的文件,并写入以下内容:

declare module '*.vue' {
  import { ComponentOptions } from 'vue'
  const componentOptions: ComponentOptions
  export default componentOptions
}

image-20230818173452269