原因:
TypeScript文件只能够理解.ts文件,无法理解.vue文件
- Vue 3 can not find module
解决办法
创建shims-vue.d.ts文件,告诉TS如何理解.vue文件
方法一
在shims-vue.d.ts文件中加入以下代码,
declare module '*.vue' {
import { Component } from 'vue'
const component: Component
export default component
}
方法二
用ComponentOptions代替方法一代码中的Component
declare module '*.vue' {
import { ComponentOptions } from 'vue'
const componentOptions : ComponentOptions
export default componentOptions
}