tmui-vx
Version:
tmui4x,uniappx
37 lines (30 loc) • 1.33 kB
JavaScript
import { defineAsyncComponent } from "vue";
export const tmui4xVw = {
install:(app) => {
// import.meta.glob是vite的新api
const components = import.meta.glob("./components/*.vue");
// 遍历组件模块实现自动注册
for (const [path, component] of Object.entries(components)) {
// 把文件名称当作组件注册的 name
const componentName = path.slice(path.lastIndexOf("/") + 1, path.lastIndexOf("."));
// 通过 defineAsyncComponent 异步导入指定路径下的组件
console.log(componentName)
app.component(componentName, defineAsyncComponent(component));
}
}
}
// 自动导入所有组件
const components = import.meta.glob("./components/*.vue", { eager: true });
// 创建组件导出对象
const componentExports = {};
// 遍历组件模块实现自动导出
for (const [path, module] of Object.entries(components)) {
// 把文件名称当作组件导出的 name
const componentName = path.slice(path.lastIndexOf("/") + 1, path.lastIndexOf("."));
// 导出组件
componentExports[componentName] = module.default;
}
// 导出所有组件
export const { Text, View } = componentExports;
// 默认导出所有组件
export default componentExports;