Skip to content

Config 全局配置

用于为 MuzhiyuUI 组件库提供全局主题(明暗模式切换)、品牌主色定制、全局层级(z-index)与单位换算等配置的 Provider 容器组件。同时导出 JS 全局样式配置对象。


代码示例

1. 动态主题切换 (Theme Switch)

使用 <mu-config> 容器包裹组件,通过 theme 属性动态切换全套明暗主题。

vue
<template>
  <mu-config :theme="isDark ? 'dark' : 'light'">
    <div class="app-container">
      <mu-button type="primary">主题联动按钮</mu-button>
    </div>
  </mu-config>
</template>

<script setup>
import { ref } from 'vue'
const isDark = ref(false)
</script>

2. 品牌主色动态定制 (Primary Color)

通过 primary-color 传入自定义主色(如 #3B82F6#10B981),为内部组件注入 CSS 变量 --mu-primary

vue
<template>
  <mu-config primary-color="#3B82F6">
    <mu-button type="primary">自定义蓝色主色按钮</mu-button>
  </mu-config>

  <mu-config primary-color="#10B981">
    <mu-button type="primary">自定义绿色主色按钮</mu-button>
  </mu-config>
</template>

3. JavaScript 默认样式配置导出 (Config Object)

组件库导出了默认的核心样式字典对象,可直接引入用于自定义逻辑计算:

js
import defaultConfig from 'muzhiyu-ui/components/mu-config/index.js'

console.log(defaultConfig.primaryColor) // '#1677FF'
console.log(defaultConfig.duration)     // 200 (ms)

API 属性说明 (Props)

参数名说明类型可选值默认值
theme全局主题模式Stringlight | dark'light'
primaryColor自定义品牌主色String-'#171717'
zIndex基础浮层 z-index 初始层级Number-1000
unit全局响应式长度单位Stringrpx | px'rpx'

插槽说明 (Slots)

插槽名说明
default需要注入全局配置的主视图容器或组件树

基于 MIT 协议开源发行

H5 模拟器 (config)☀️🔄