uView UI Documentation
repository·master·Indexed 26 days ago
https://github.com/umicro/uviewA comprehensive UI framework for rapid multi-platform development within the uni-app ecosystem. uView UI provides over 60 high-quality components and utility tools compatible with Android, iOS, WeChat Mini Program, H5, and other mini-program platforms. It features automatic component loading via easycom and includes specialized components such as u-avatar, u-calendar, u-field, and u-form for data validation.
What's inside uView UI
- You can download the uView UI plugin from the DCloud extension marketplace: https://ext.dcloud.net.cn/plugin?id=1593
Install uView UI via npm
masterInstall the
uview-uipackage using npm to add the UI framework to your uni-app project.npm i uview-uiUse uView components with easycom
masterOnce the
easycomrule is configured inpages.json, you do not need to manuallyimportcomponents. You can use them directly in your templates by prefixing the component name withu-.<template> <u-button>按钮</u-button> </template>Install and Setup uView UI
masteruView UI is a UI framework for the uni-app ecosystem. To use it, follow these four setup steps:
- Register the library in
main.js - Import base styles in
App.vue(ensure the<style>tag has thelang="scss"attribute). - Import global SCSS variables in
uni.scss. - Configure
easycominpages.jsonto enable automatic component loading (on-demand import).
Note: The
easycomconfiguration pattern differs depending on whether you installed via download or via npm.// 1. main.js import uView from 'uview-ui'; Vue.use(uView); // 2. App.vue <style lang="scss"> @import "uview-ui/index.scss"; </style> // 3. uni.scss @import "uview-ui/theme.scss"; // 4. pages.json { "easycom": { // Use this for Download installation: "^u-(.*)": "@/uview-ui/components/u-$1/u-$1.vue" // Use this for npm installation: // "^u-(.*)": "uview-ui/components/u-$1/u-$1.vue" } }- Register the library in
Configure uView UI for quick start
masterTo use uView UI in a uni-app project, follow these four configuration steps:
- Register the library in
main.js: ImportuViewand use it with Vue. - Import base styles in
App.vue: Import the main SCSS file. Ensure your<style>tag includeslang="scss". - Import global variables in
uni.scss: Import the theme SCSS file to enable global variable support. - Configure
easycominpages.json: Add theeasycomrule to enable automatic component loading (on-demand import).
// 1. main.js import uView from 'uview-ui'; Vue.use(uView); // 2. App.vue <style lang="scss"> @import "uview-ui/index.scss"; </style> // 3. uni.scss @import "uview-ui/theme.scss"; // 4. pages.json { "easycom": { "^u-(.*)": "uview-ui/components/u-$1/u-$1.vue" } }- Register the library in
Configure easycom for automatic component imports
masterTo enable on-demand loading of uView components without manual imports, add the following rule to your
pages.json.Note for npm users: Do NOT use the
@/prefix. Use the pathuview-ui/components/u-$1/u-$1.vue. Note for download/manual installation users: Use the@/prefix (e.g.,@/uview-ui/components/u-$1/u-$1.vue).// pages.json { "easycom": { // npm installation method "^u-(.*)": "uview-ui/components/u-$1/u-$1.vue" // Download/Manual installation method // "^u-(.*)": "@/uview-ui/components/u-$1/u-$1.vue" } }Use uView Mini-program sharing mixin
masterFor WeChat Mini-programs or other mini-program environments, uView provides a mixin to simplify the implementation of sharing features. Import it from
uview-ui/libs/mixin/mpShare.jsand apply it usingVue.mixin().// 引入uView对小程序分享的mixin封装 let mpShare = require('uview-ui/libs/mixin/mpShare.js'); Vue.mixin(mpShare);Install and initialize uView UI
masterTo use uView UI in your Vue application, import
uViewfromuview-uiand register it usingVue.use(uView). This makes uView components and utilities available globally throughout your application.import uView from 'uview-ui'; Vue.use(uView);Install and integrate uView UI
masteruView UI is a Vue plugin that can be installed into your application. Upon installation, it performs the following actions:
- Registers a global mixin.
- Adds global filters for time formatting:
timeFormat,date, andtimeFrom. - Mounts the
$uutility object to the Vue prototype (this.$u) and the globaluniobject (uni.$u).
To use it in a Vue-based uni-app project, use the
installmethod provided by the default export.Use the u-avatar-cropper component
masterThe
u-avatar-croppercomponent allows users to select and crop an image for an avatar. You can configure the output dimensions, the cropping area size, and the file format via theroutemethod.When the cropping process is complete, the component emits the resulting image path via the global
uni.$on('uAvatarCropper', callback)event listener.Use uView Vuex mixin
masteruView provides a shorthand mixin for Vuex to simplify state management access. You can integrate it by requiring the mixin file from
@/store/$u.mixin.jsand applying it viaVue.mixin().// 引入uView提供的对vuex的简写法文件 let vuexStore = require('@/store/$u.mixin.js'); Vue.mixin(vuexStore);Use uView UI components
masterOnce
easycomis configured inpages.json, you can use uView components directly in your templates without importing them manually.<template> <u-button>按钮</u-button> </template>