mirror of
https://github.com/talktao/Vue3-Vite-Vant-TS-H5.git
synced 2025-04-06 03:57:55 +08:00
fix:重写components.ts
This commit is contained in:
parent
d7d21b3b89
commit
d58ea4ef24
@ -1,22 +1,13 @@
|
||||
|
||||
const modules = import.meta.globEager('../components/*.vue')
|
||||
|
||||
export default {
|
||||
install(app) {
|
||||
Object.keys(modules).forEach(componentPath => {
|
||||
|
||||
let splitPart1 = componentPath.split("/")
|
||||
let componentName = splitPart1[splitPart1.length - 1].split(".vue")[0]
|
||||
// 获取遍历的当前组件实例对象
|
||||
let curComponent = modules[componentPath]?.default
|
||||
|
||||
// 获取所有组件的实例对象,它是个数组
|
||||
let modulesData = Object.values(modules).map((v) => v.default)
|
||||
|
||||
// 过滤出当前组件的实例对象与注册组件匹配一致
|
||||
let curComponent = modulesData.filter(
|
||||
item=>item.__file.split("/")[item.__file.split("/").length-1].split(".vue")[0] === componentName
|
||||
)[0]
|
||||
|
||||
app.component(componentName, curComponent);
|
||||
app.component(curComponent.name, curComponent);
|
||||
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user