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:
app.use(uViewProX, {
config: {
unit: 'px',
debugMode: true,
componentProps: {
'ux-back-top': { fontSize: '19px' }
}
}
})Configurable fields
| Field | Type | Default | Description |
|---|---|---|---|
version | string | library version | Version number (redundant field) |
type | string[] | ['primary','success','error','warning','info'] | Type token list, used for CSS variable prefix detection |
defaultTheme | string | 'uviewpro' | Default theme name |
defaultDarkMode | DarkMode | 'light' | Default dark mode |
defaultLocale | string | 'zh-CN' | Default language |
debugMode | boolean | DebugMode | DebugMode[] | false | Debug switch / level (log / warn / error / info) |
unit | string | 'px' | Unit used when composing size values |
componentProps | UTSJSONObject | {} | 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:
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:
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
configis reactive: modifying$u.configor calling$u.setConfigat runtime takes effect immediately; however, internal state already derived from defaults in rendered components may not backtrack, so finish configuration during app startup.typeparticipates 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.componentPropsis deep-merged: repeated calls merge layer by layer rather than replacing existing config.unitaffects composed sizes (e.g.addUnit). Switching torpxchanges every default size that relies on it, so re-check layouts.defaultTheme/defaultDarkMode/defaultLocaleoverlap with thetheme/localeinstall options; the latter override the corresponding config item during initialization, so maintain only one of the two.