u
This commit is contained in:
1 parent
208f6e3124
commit
8f4c696bdd
23 files changed
+1060
-330
No files matched your search
@@ -0,0 +1,41 @@
|
||||
import type { App, Component } from 'vue'
|
||||
// components/index.ts(修改后)
|
||||
|
||||
import * as comps from './components'
|
||||
|
||||
// 按需导出组件(可单独 import)
|
||||
export * from './components'
|
||||
|
||||
// 收集所有组件
|
||||
const allComponents = Object.values(comps).filter(
|
||||
(c: any) => c && c.name,
|
||||
) as Component[]
|
||||
|
||||
export interface AoDesignOptions {
|
||||
prefix?: string
|
||||
components?: Component[] // 按需注册时传入需要注册的组件
|
||||
}
|
||||
|
||||
const AoDesign = {
|
||||
install(app: App, options: AoDesignOptions = {}) {
|
||||
const prefix = options?.prefix ?? 'A'
|
||||
// 如果用户指定了 components,则只注册这些,否则注册全部
|
||||
const componentsToRegister = options?.components || allComponents
|
||||
|
||||
componentsToRegister.forEach((component: any) => {
|
||||
if (!component?.name)
|
||||
return
|
||||
|
||||
const name = `${prefix}${component.name}`
|
||||
|
||||
app.component(name, component)
|
||||
// 注册 kebab-case
|
||||
app.component(
|
||||
name.replace(/([A-Z])/g, '-$1').toLowerCase().replace(/^-/, ''),
|
||||
component,
|
||||
)
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
export default AoDesign
|
||||
Reference in new issue
Block a user