解决自动导入自定义组件的效果,类似于uni-ui自动导入,配置easycom
在pages.json中
"easycom": {
"autoscan": true,
"custom": {
// uni-ui 规则如下配置
"^uni-(.*)": "@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue",
// 自定义导入components中的自定义组件
"^Xtx(.*)": "@/components/Xtx$1.vue"
}
解释:
- ^组件以什么开头
- (.*)匹配到的内容
- $1插入匹配到的内容
全局组件类型声明
// src/types/components.d.ts
import XtxSwiper from './XtxSwiper.vue'
declare module 'vue' {
export interface GlobalComponents {
XtxSwiper: typeof XtxSwiper
}
}
注意
版本升级
新版 Volar 把 declare module '@vue/runtime-core'
调整为 declare module 'vue'