base-vue支持组件库支持前缀类名
This commit is contained in:
1 parent
8f4c696bdd
commit
8bd73b3786
18 files changed
+266
-152
No files matched your search
@@ -0,0 +1,8 @@
|
||||
import type { InjectionKey } from 'vue'
|
||||
|
||||
export interface ConfigProviderContext {
|
||||
prefixCls: string
|
||||
}
|
||||
|
||||
export const configProviderInjectionKey: InjectionKey<ConfigProviderContext>
|
||||
= Symbol('ConfigProvider')
|
||||
@@ -0,0 +1,26 @@
|
||||
import { defineComponent, getCurrentInstance, provide, reactive, toRefs } from 'vue'
|
||||
import { configProviderInjectionKey } from './context'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ConfigProvider',
|
||||
props: {
|
||||
prefixCls: { type: String, default: 'ao' },
|
||||
global: { type: Boolean, default: false },
|
||||
},
|
||||
setup(props, { slots }) {
|
||||
const { prefixCls } = toRefs(props)
|
||||
const config = reactive({ prefixCls: prefixCls.value })
|
||||
|
||||
if (props.global) {
|
||||
const instance = getCurrentInstance()
|
||||
if (instance) {
|
||||
instance.appContext.app.provide(configProviderInjectionKey, config)
|
||||
}
|
||||
}
|
||||
else {
|
||||
provide(configProviderInjectionKey, config)
|
||||
}
|
||||
|
||||
return () => slots.default?.()
|
||||
},
|
||||
})
|
||||
Reference in new issue
Block a user