uView Pro Documentation

repository·master·Indexed 19 days ago

https://github.com/anyup/uview-pro

A multi-platform UI framework for uni-app built with Vue 3 and TypeScript. It supports Android, iOS, HarmonyOS, and various mini-programs (WeChat, Alipay, etc.). The framework includes features such as the vite-plugin-uni-root for global root component injection and the zero-markdown-view component for rendering Markdown content with specialized AI streaming mode support.

Tokens
171.9K
Snippets
566
Records
748
Agent score
67%

What's inside uView Pro

  1. Overview of uView Pro components

    master

    uView Pro is a comprehensive component library for Vue3 and TypeScript, supporting multiple platforms including Android, iOS, WeChat Mini Programs, and H5. It features over 70 components categorized as follows:

    Basic Components

    • Color, Icon, Image, Button, Layout, Cell, Badge, Tag

    Form Components

    • Form, Calendar, Select, Keyboard, Picker, Rate, Search, NumberBox, Upload, VerificationCode, Field, Checkbox, Radio, Switch, Slider

    Data Components

    • Progress, Table, CountDown, CountTo

    Feedback Components

    • ActionSheet, AlertTips, Toast, NoticeBar, TopTips, SwipeAction, Collapse, Popup, Modal, fullScreen

    Layout Components

    • Line, Card, Mask, NoNetwork, Grid, Swiper, TimeLine, Skeleton, Sticky, Waterfall, Divider
    • Dropdown, Tabbar, BackTop, Navbar, Tabs, TabsSwiper, Subsection, IndexList, Steps, Empty, Section

    Other Components

    • MessageInput, Loadmore, ReadMore, LazyLoad, Gap, Avatar, Link, Loading
  2. Overview of uView Pro

    master

    uView Pro is a UI framework designed for rapid multi-platform development using uni-app and Vue3. It is specifically built to serve the uni-app ecosystem, enabling developers to write a single codebase that can be deployed to iOS, Android, H5, and various mini-programs (including WeChat, Alipay, Baidu, Toutiao, QQ, and DingTalk).

    Key Characteristics:

    • Vue3 Native: Fully refactored using Vue3 syntax.
    • Backward Compatibility: Designed to maintain the existing API patterns of uView UI 1.x, allowing developers to migrate from Vue2/uView 1.x to Vue3/uView Pro with minimal friction.
    • License: Distributed under the MIT license, allowing free use in commercial products (provided they do not involve illegal activities like gambling or violence).
  3. Use the u-picker component

    master

    The u-picker component is a versatile selector supporting four modes: time (time selection), region (area/location selection), selector (single-column selection), and multiSelector (multi-column selection).

    Note: Since version 1.3.0, it is recommended to use the Select component instead of selector or multiSelector modes, as it is more user-friendly. The u-picker component is now primarily focused on time and region selection.

    To control the visibility of the picker, use v-model bound to a boolean variable.

    <template>
    	<view>
    		<u-picker v-model="show" mode="time"></u-picker>
    		<u-button @click="show = true">打开</u-button>
    	</view>
    </template>
    
    <script>
    	export default {
    		data() {
    			return {
    				show: false
    			}
    		}
    	}
    </script>
  4. Use the u-select component for column selection

    master

    The u-select component is designed for single-column, multi-column, and multi-column linked selection scenarios. It is recommended over the Picker component for these specific use cases.

    Data Requirements

    All modes require the list array elements to be objects containing value and label properties. You can customize these keys using value-name and label-name props.

    • value: Used to distinguish the selection in callbacks.
    • label: The text displayed to the user.
    • extra (Optional): If you include an extra property in your list objects, it will be returned in the confirm event callback.

    Basic Usage

    Use v-model with a boolean variable to control the visibility (popup/collapse) of the selector.

    <template>
      <view>
        <u-select v-model="show" :list="list"></u-select>
        <u-button @click="show = true">Open</u-button>
      </view>
    </template>
    
    <script>
      export default {
        data() {
          return {
            show: false,
            list: [
              { value: '1', label: 'Jiang' },
              { value: '2', label: 'Hu' }
            ],
          }
        }
      }
    </script>
    <u-select v-model="show" :list="list"></u-select>
  5. Use the u-input component

    master

    The u-input component is an input field designed to work seamlessly with the u-form component for form validation and data entry.

    Usage Note:

    • If you only need a simple input field without form validation, consider using u-field instead.
    • For form groups requiring validation, nest u-input inside u-form-item, which is itself inside a u-form.
    <template>
    	<u-input v-model="value" :type="type" :border="border" />
    </template>
    
    <script>
    	export default {
    		data() {
    			return {
    				value: '',
    				type: 'text',
    				border: true
    			}
    		}
    	}
    </script>
  6. Use the u-field component for form input

    master

    The u-field component is used for form inputs, supporting both single-line text and multi-line textarea types. It can be integrated with other uView components like picker or actionSheet to create selection-based inputs (e.g., for gender, time, or region selection) by setting disabled to true and using a right-icon.

    <template>
    	<view>
    		<u-field
    			v-model="mobile"
    			label="手机号"
    			placeholder="请填写手机号"
    		></u-field>
    		<u-field
    			v-model="code"
    			label="验证码"
    			placeholder="请填写验证码"
    		></u-field>
    	</view>
    </template>
    
    <script>
    	export default {
    		data() {
    			return {
    				mobile: '',
    				code: ''
    			}
    		}
    	}
    </script>
  7. Use the uView Pro Http library

    master

    uView Pro provides a lightweight HTTP request library for uni-app that supports TypeScript, Vue3, and Composition API. It supports get, post, put, and delete methods. It is designed for medium-to-small projects and includes built-in support for global/single-request configuration of toast and loading states, as well as request/response interceptors.

    Note: Currently, this library does not support file uploads or downloads.

    import { http } from 'uview-pro'
    
    // GET
    http.get('/api/user', { id: 1 }).then(res => {
      /* ... */
    })
    
    // POST
    http.post('/api/login', { username: 'xx', password: 'xx' }).then(res => {
      /* ... */
    })
    
    // PUT/DELETE
    http.put('/api/user/1', { name: 'new' })
    http.delete('/api/user/1')
  8. What is the tabsSwiper component?

    master

    The tabsSwiper component provides a full-screen tab navigation experience. It is built upon uni-app's scroll-view and swiper components.

    Key Features:

    • Smooth transitions with color gradients for tab text.
    • A bottom slider (bar) that follows the sliding motion.
    • Automatic centering of the active tab during scrolling.

    Comparison with tabs component:

    • tabs: Simpler to use, does not require a swiper component, but lacks the sliding bar and color gradient effects.
    • tabsSwiper: More complex configuration, but provides the enhanced sliding and visual effects. It must be used in conjunction with a uni-app swiper component.

    Important Limitations:

    • Alipay Mini Programs: Not supported because Alipay does not support the dx parameter in the swiper component's transition event.
    • Performance: It is currently a vue version (not nvue). It is suitable for simple lists. For very complex, long lists (like a news app home page), use caution and test performance, as swiper can have performance overhead with large amounts of content.
  9. Configure Col span and offset

    master

    The u-col component defines how much space an individual column occupies within the 12-column grid:

    • Span: Use the span prop to set the number of columns the element occupies (1-12). Default is 0.
    • Offset: Use the offset prop to shift the column to the right by a specific number of columns. This uses the same calculation logic as span.
    • Text Alignment: Use the text-align prop to align text within the column.
      • Options: left (default), center, right.
    <u-row gutter="16">
    	<u-col span="3"></u-col>
    	<u-col span="3" offset="6"></u-col>
    </u-row>
  10. Manually trigger loading with the loadmore event

    master
    When the status is set to loadmore, the component is interactive. If a user clicks the component, it emits the loadmore event. This is useful for handling cases where network issues or insufficient data prevent the automatic onReachBottom lifecycle event from firing. You can listen for this event to trigger your data loading logic.
  11. Distinguish between disabled and readonly states in u-field

    master

    The u-field component provides two distinct non-interactive states:

    1. Disabled (disabled): The field is completely inactive. The user cannot input text and cannot trigger @click events.
    2. Readonly (readonly): The field is non-editable, but it remains interactive. The user can still trigger @click events (useful for opening pickers or triggering specific actions), but they cannot change the text value.
    <!-- Disabled: No input, no click -->
    <u-field
      v-model="disabledValue"
      label="禁用状态"
      disabled
    />
    
    <!-- Readonly: No input, but can be clicked -->
    <u-field
      v-model="readonlyValue"
      label="只读状态"
      readonly
      @click="onReadonlyClick"
    />
  12. Optimize usage of uni.scss

    master

    The uni.scss file is automatically injected into every file using lang="scss". To prevent bloating your final package size:

    • Do: Only place SCSS variables (colors, themes, sizes) in uni.scss.
    • Don't: Put large amounts of CSS rules or complex logic in uni.scss, as this content will be duplicated into every single SCSS-enabled component in your project.