新建一个 components.d.ts 文件 (xxx.d.ts文件为类型声明文件)
// 全局组件类型声明提示
// components.d.ts
// 引进本地组件文件
import Skeleton from './Skeleton/Skeleton.vue';
import Button from './Button/index.vue';
declare module 'vue' {
// 全局组件需通过 GlobalComponents 接口定义(Volar文档中说明)
export interface GlobalComponents {
// 全局组件名: 组件类型;
// vue-router 的两个全局组件,添加类型声明
RouterLink: typeof import('vue-router')['RouterLink'];
RouterView: typeof import('vue-router')['RouterView'];
// 自己的全局组件注册类型声明, typeof 表示基于获取组件的TS类型
XtxButton: typeof Button;
XtxSkeleton: typeof Skeleton;
}
}
export {};