开发指南

一、在 src/components 目录下创建新组件

二、在 src/index.ts 文件中添加组件

      // 导入新组件
import uploadCos from '../Upload/uploadCos.vue';
import uploadLocal from '../Upload/uploadLocal.vue';
import newComponent from '../Your/NewComponent.vue'; // 添加新组件导入

// 组件注册表 - 只需要在这里添加新组件
const componentList = {
    uploadCos,
    uploadLocal,
    newComponent // 添加新组件到注册表
};
    

三、 在 types/index.d.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>; // 添加默认导出类型
};
    

四、 更新版本号并发布:

      # 修改 package.json 中的版本号
pnpm pub
    

声明

作者: liyao

版权:本博客所有文章除特别声明外,均采用CCBY-NC-SA4.O许可协议。转载请注明!

最后更新于 2025-09-30 20:31 history