Appearance
基于本库开发新组件
开发指南
1. 在 src/components
目录下创建新组件
2. 在 src/index.ts
文件中添加组件:
js
// 导入新组件
import uploadCos from '../Upload/uploadCos.vue';
import uploadLocal from '../Upload/uploadLocal.vue';
import newComponent from '../Your/NewComponent.vue'; // 添加新组件导入
// 组件注册表 - 只需要在这里添加新组件
const componentList = {
uploadCos,
uploadLocal,
newComponent // 添加新组件到注册表
};
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
3. 在 types/index.d.ts
文件中添加类型声明,需要在四个地方添加:
ts
// 1. 导入时的组件类型定义
declare module 'liyao-vue-common' {
export const uploadCos: DefineComponent<{}, {}, any>;
export const uploadLocal: DefineComponent<{}, {}, any>;
export const newComponent: DefineComponent<{}, {}, any>; // 添加新组件类型
export const install: (app: App) => void;
}
// 2. Vue 全局组件类型定义
declare module 'vue' {
export interface GlobalComponents {
uploadCos: DefineComponent<{}, {}, any>;
uploadLocal: DefineComponent<{}, {}, any>;
newComponent: DefineComponent<{}, {}, any>; // 添加全局组件类型
}
}
// 3. 组件文件模块声明
declare module '@/components/Upload/uploadCos.vue' {
const component: DefineComponent<{}, {}, any>;
export default component;
}
declare module '@/components/Upload/uploadLocal.vue' {
const component: DefineComponent<{}, {}, any>;
export default component;
}
// 添加新组件的模块声明
declare module '@/components/Your/NewComponent.vue' {
const component: DefineComponent<{}, {}, any>;
export default component;
}
// 4. 默认导出
declare const _default: {
install: (app: App) => void;
uploadCos: DefineComponent<{}, {}, any>;
uploadLocal: DefineComponent<{}, {}, any>;
newComponent: DefineComponent<{}, {}, any>; // 添加默认导出类型
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
4. 更新版本号并发布:
bash
# 修改 package.json 中的版本号
pnpm pub
1
2
2