Skip to content

useConfigProvider

用于在 JS 逻辑中注入全局配置(如主题变量),解决在微信小程序等环境中,由于组件渲染机制限制(如原生插槽作用域隔离)或使用 root-portal 导致无法获取父级 ConfigProvider 配置的问题。

提示

需要和 ConfigProvider 组件配合使用,使用 ConfigProvider 组件包裹你的组件。用于解决小程序端依赖注入的限制,导致部分场景下无法获取父级 ConfigProvider 配置的问题。

基础用法

ts
import { useConfigProvider } from '@/uni_modules/wot-ui'
import { reactive, ref } from 'vue'

// 使用 reactive
const themeVars = reactive({
  primary6: '#ff4d4f',
  buttonPrimaryBg: '#07c160'
})

useConfigProvider({ themeVars, button: { size: 'small', variant: 'plain' } })

// 或者使用 ref
const themeVarsRef = ref({
  primary6: '#2c68ff'
})

useConfigProvider({ themeVars: themeVarsRef, button: { size: 'large', type: 'success', round: true }, tag: { size: 'medium', variant: 'light', round: true } })

API

参数

参数说明类型默认值最低版本
themeVars主题变量对象,支持响应式更新ConfigProviderThemeVars | Ref<ConfigProviderThemeVars>-1.14.0
theme主题风格,可选值为 lightdarkstring | Ref<string>'light'1.14.0
buttonButton 组件全局配置,支持 size / variant / type / round{ size?: string; variant?: string; type?: string; round?: boolean } | Ref<ButtonConfig>{}-
tagTag 组件全局配置,支持 size / variant / round{ size?: string; variant?: string; round?: boolean } | Ref<TagConfig>{}-

Released under the MIT License.

Released under the MIT License.