uView UI Documentation

repository·master·Indexed 26 days ago

https://github.com/umicro/uview

A 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.

Tokens
30K
Snippets
75
Records
152
Agent score
87%

What's inside uView UI

  1. Use uView components with easycom

    master

    Once the easycom rule is configured in pages.json, you do not need to manually import components. You can use them directly in your templates by prefixing the component name with u-.

    <template>
    	<u-button>按钮</u-button>
    </template>
  2. Install and Setup uView UI

    master

    uView UI is a UI framework for the uni-app ecosystem. To use it, follow these four setup steps:

    1. Register the library in main.js
    2. Import base styles in App.vue (ensure the <style> tag has the lang="scss" attribute).
    3. Import global SCSS variables in uni.scss.
    4. Configure easycom in pages.json to enable automatic component loading (on-demand import).

    Note: The easycom configuration 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"
    	}
    }
  3. Configure uView UI for quick start

    master

    To use uView UI in a uni-app project, follow these four configuration steps:

    1. Register the library in main.js: Import uView and use it with Vue.
    2. Import base styles in App.vue: Import the main SCSS file. Ensure your <style> tag includes lang="scss".
    3. Import global variables in uni.scss: Import the theme SCSS file to enable global variable support.
    4. Configure easycom in pages.json: Add the easycom rule 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"
    	}
    }
  4. Configure easycom for automatic component imports

    master

    To 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 path uview-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"
    	}
    }
  5. Use uView Mini-program sharing mixin

    master

    For 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.js and apply it using Vue.mixin().

    // 引入uView对小程序分享的mixin封装
    let mpShare = require('uview-ui/libs/mixin/mpShare.js');
    Vue.mixin(mpShare);
  6. Install and initialize uView UI

    master

    To use uView UI in your Vue application, import uView from uview-ui and register it using Vue.use(uView). This makes uView components and utilities available globally throughout your application.

    import uView from 'uview-ui';
    Vue.use(uView);
  7. Install and integrate uView UI

    master

    uView UI is a Vue plugin that can be installed into your application. Upon installation, it performs the following actions:

    1. Registers a global mixin.
    2. Adds global filters for time formatting: timeFormat, date, and timeFrom.
    3. Mounts the $u utility object to the Vue prototype (this.$u) and the global uni object (uni.$u).

    To use it in a Vue-based uni-app project, use the install method provided by the default export.

  8. Use the u-avatar-cropper component

    master

    The u-avatar-cropper component 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 the route method.

    When the cropping process is complete, the component emits the resulting image path via the global uni.$on('uAvatarCropper', callback) event listener.

  9. Use uView Vuex mixin

    master

    uView provides a shorthand mixin for Vuex to simplify state management access. You can integrate it by requiring the mixin file from @/store/$u.mixin.js and applying it via Vue.mixin().

    // 引入uView提供的对vuex的简写法文件
    let vuexStore = require('@/store/$u.mixin.js');
    Vue.mixin(vuexStore);