vue3.2/Vite/Ts12: 自定义插件注册 SVG 全局组件
·
Yin灏
第一步:新建注册处理文件
新建 src / components / index.ts
import SvgIcon from "./SvgIcon/index.vue";
import Pagination from "./Pagination/index.vue";
const allGlobalComponent = {
SvgIcon,
Pagination,
};
export default {
// 必须叫做 install 方法
install(app) {
Object.keys(allGlobalComponent).forEach((key) => {
app.component(key, allGlobalComponent[key]);
});
},
};
第二步:main.ts 引入自定义插件
// 引入
import globalComponent from "@/components";
//...
// 安装
app.use(globalComponent);
//...