mirror of
https://github.com/talktao/Vue3-Vite-Vant-TS-H5.git
synced 2025-04-23 18:00:21 +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')
|
const modules = import.meta.globEager('../components/*.vue')
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
install(app) {
|
install(app) {
|
||||||
Object.keys(modules).forEach(componentPath => {
|
Object.keys(modules).forEach(componentPath => {
|
||||||
|
|
||||||
let splitPart1 = componentPath.split("/")
|
// 获取遍历的当前组件实例对象
|
||||||
let componentName = splitPart1[splitPart1.length - 1].split(".vue")[0]
|
let curComponent = modules[componentPath]?.default
|
||||||
|
|
||||||
// 获取所有组件的实例对象,它是个数组
|
app.component(curComponent.name, curComponent);
|
||||||
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);
|
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user