Skip to content

Global Config ​

The library's global configuration lives on a single reactive config object. It can be passed at install time and read / modified at runtime via $u.config and $u.setConfig. It manages the unit, default theme, default locale, debug mode, and per-component defaults.

Configure at install time ​

Set it via the config option in app.use in main.uts:

ts
app.use(uViewProX, {
    config: {
        unit: 'px',
        debugMode: true,
        componentProps: {
            'ux-back-top': { fontSize: '19px' }
        }
    }
})

Configurable fields ​

FieldTypeDefaultDescription
versionstringlibrary versionVersion number (redundant field)
typestring[]['primary','success','error','warning','info']Type token list, used for CSS variable prefix detection
defaultThemestring'uviewpro'Default theme name
defaultDarkModeDarkMode'light'Default dark mode
defaultLocalestring'zh-CN'Default language
debugModeboolean | DebugMode | DebugMode[]falseDebug switch / level (log / warn / error / info)
unitstring'px'Unit used when composing size values
componentPropsUTSJSONObject{}Per-component default overrides

Empty values do not override

setConfig keeps the default for empty values (empty string, empty array, null, etc.), so you only pass the fields you want to change.

Read and modify at runtime ​

Access it through the global $u object:

ts
import { $u } from '@/uni_modules/uview-pro-x'

// Read
console.log($u.config.unit)          // 'px'
console.log($u.config.defaultTheme)  // 'uviewpro'

// Modify (in-place merge; empty values do not override)
$u.setConfig({ unit: 'rpx' })

Per-component defaults ​

componentProps sets project-level defaults for a component's props without touching its source. The key is the component name (ux- prefix) and the value is a partial set of that component's props:

ts
app.use(uViewProX, {
    config: {
        componentProps: {
            'ux-back-top': { fontSize: '19px' },
            'ux-button': { size: 'large' }
        }
    }
})

The priority for a component's value is: prop passed at the call site > componentProps config > the component's own withDefaults default. So componentProps only affects calls that do not pass a value explicitly.

Notes ​

  1. config is reactive: modifying $u.config or calling $u.setConfig at runtime takes effect immediately; however, internal state already derived from defaults in rendered components may not backtrack, so finish configuration during app startup.
  2. type participates in CSS variable prefix detection: a token prefixed by any of its values produces a --u-type-* variable. Changing it affects theme variable naming, so avoid it unless necessary.
  3. componentProps is deep-merged: repeated calls merge layer by layer rather than replacing existing config.
  4. unit affects composed sizes (e.g. addUnit). Switching to rpx changes every default size that relies on it, so re-check layouts.
  5. defaultTheme / defaultDarkMode / defaultLocale overlap with the theme / locale install options; the latter override the corresponding config item during initialization, so maintain only one of the two.