uView 2.0 Documentation

repository·master·Indexed 23 days ago

https://github.com/umicro/uview2.0

A comprehensive UI framework for the uni-app ecosystem, supporting multi-platform development for iOS, Android, H5, and various mini-programs (WeChat, QQ, Baidu, Alipay, Toutiao). It features over 60 components, nvue compatibility, on-demand imports via easycom, and a suite of JS utility tools accessible through the uni.$u object, including HTTP request handling via luch-request, date formatting, and object manipulation.

Tokens
3.3K
Snippets
3
Records
23
Agent score
83%

What's inside uView 2.0

  1. Overview of uView 2.0

    master

    uView 2.0 is a UI framework designed for the uni-app ecosystem. It is fully compatible with nvue and provides a comprehensive set of components and utility tools for rapid multi-platform development.

    Key Features

    • Multi-platform Compatibility: Supports Android, iOS, WeChat Mini Program, H5, QQ Mini Program, Baidu Mini Program, Alipay Mini Program, and Toutiao Mini Program.
    • High Performance: Fully compatible with nvue for native rendering.
    • Rich Component Library: Over 60 selected components that are ready to use out of the box.
    • Utility Tools: Includes various JS utilities to simplify development.
    • Layouts & Pages: Provides common page layouts to help developers focus on business logic.
    • Optimized Bundle Size: Supports on-demand (tree-shaking) imports to keep the final package small.
    • Documentation: Detailed documentation with modern live demonstrations.
  2. Use uView 2.0 components with easycom

    master

    uView 2.0 supports the easycom mechanism. Once configured, components are automatically imported on demand. You do not need to manually import components; you can use them directly in your templates.

    Example usage:

    <template>
    	<u-button text="按钮"></u-button>
    </template>
  3. Component categories in uView UI

    master

    uView UI components are organized into several functional groups. When browsing the documentation or example pages, you can find components categorized as follows:

    • Basic components (基础组件): Core UI elements like Color, Icon, Image, Button, Text, Layout, Cell, Badge, Tag, and Loading indicators.
    • Form components (表单组件): Input-related elements such as Form, Calendar, Keyboard, Picker, DatetimePicker, Rate, Search, NumberBox, Upload, Code (verification), Input, Textarea, Checkbox, Radio, Switch, Slider, and Album.
    • Data components (数据组件): Elements for displaying data, including List, Progress, CountDown, and CountTo.
    • Feedback components (反馈组件): UI elements that provide user feedback, such as Tooltip, ActionSheet, Alert, Toast, NoticeBar, Notify, SwipeAction, Collapse, Popup, and Modal.
    • Layout components (布局组件): Structural elements like ScrollList, Line, Overlay, NoNetwork, Grid, Swiper, Skeleton, Sticky, and Divider.
    • Navigation components (导航组件): Elements for navigating the application, including Tabbar, BackTop, Navbar, Tabs, Subsection, IndexList, Steps, and Empty states.
    • Other components (其他组件): Miscellaneous utilities like Parse (rich text), CodeInput, Loadmore, ReadMore, Gap, Avatar, Link, and Transition animations.
  4. Install and configure uView UI

    master

    To use uView UI, you must install the library and ensure your environment is configured to handle its dependencies.

    Important: CLI Mode Configuration If you encounter errors related to dependency transpilation, you must configure transpileDependencies in your vue.config.js file. Refer to the official documentation for specific settings: https://www.uviewui.com/components/npmSetting.html#_5-cli模式额外配置.

    Installation via Vue Plugin The library provides an install function that should be used during your Vue initialization. This function performs the following:

    1. Registers global filters: timeFormat, date, and timeFrom.
    2. Mounts the $u object to Vue.prototype (except in nvue environments).
    3. Applies global mixins.
  5. Configure Webpack and DevServer in vue.config.js

    master

    You can customize the development server behavior by using the configureWebpack property in vue.config.js.

    Specifically, setting devServer.disableHostCheck: true allows for network tunneling (内网穿透), enabling external users or devices on different networks to access your local H5 development pages during debugging.

    module.exports = {
        configureWebpack: {
            devServer: {
                // 调试时允许内网穿透,让外网的人访问到本地调试的H5页面
                disableHostCheck: true
            }
        }
    }
  6. Reference the uni.$u utility object properties

    master

    The uni.$u object provides the following organized utilities:

    PropertyDescription
    routeRoute encapsulation utilities
    dateAlias for timeFormat
    colorGradientColor gradient function
    hexToRgbConverts Hex to RGB
    rgbToHexConverts RGB to Hex
    colorToRgbaConverts color to RGBA
    testRule validation/testing functions
    typeStandard theme types: ['primary', 'success', 'error', 'warning', 'info']
    httpAn instance of luch-request for HTTP requests
    configuView configuration information (e.g., version)
    zIndexConfiguration for fixed element z-index values
    debounceDebounce function
    throttleThrottle function
    mixinGlobal mixin
    mpMixinMini-program specific mixin
    propsProps configuration information
    colorColor configuration for special scenarios
    platformPlatform detection utilities
    ...indexSpread of additional utility functions from libs/function/index.js (e.g., timeFormat, timeFrom)
  7. Generate unique IDs with guid()

    master

    The guid(len, firstU, radix) function generates a unique identifier.

    • len: Length of the UUID (default 32). If omitted, it generates a standard RFC4122-like UUID.
    • firstU: If true (default), the first character is replaced with 'u'. This ensures the ID is a valid CSS class or HTML ID (which cannot start with a digit).
    • radix: The base for random character selection (e.g., 10 for decimal, 16 for hex).