uni-ui-plus Component Library
website·Indexed 29 days ago
https://uni-ui-plus-docs.netlify.appA modern component library built with Vue 3 and TypeScript specifically for the uni-app ecosystem. It features a variety of high-quality components including Waterfall layouts, LivePhoto support, Skeleton screens, and an enhanced List component with virtual scrolling, as well as built-in dark mode support via ConfigProvider.
What's inside uni-ui-plus
- uni-ui-plus is a modern component library specifically designed for the uni-app ecosystem. It is built using Vue 3 and TypeScript to provide a set of high-quality components with a robust type system. It supports multiple platforms, including WeChat Mini Programs, Alipay Mini Programs, DingTalk Mini Programs, H5, and native Apps.
Skeleton and Empty State components
The library includes utility components for loading and empty states:
- Skeleton Screen: A skeleton screen component for representing loading content (added in v0.0.57).
- Empty State: A component to display when no data is available (added in v0.0.58).
Swiper component features
The swiper component provides a sliding interface with customizable features and navigation controls (introduced in v0.0.67).Waterfall component overview
The waterfall component provides a masonry-style layout. It supports custom image source retrieval methods to manage how images are loaded into the layout (introduced in v0.0.60).Customize Img loading and error states using slots
The Img component provides two slots to replace the default loading and error UI with custom content:
loading: Content to display while the image is loading.error: Content to display after the image fails to load.
<up-image src="..."> <template #loading> <view>Custom Loading Spinner...</view> </template> <template #error> <view>Custom Error Icon...</view> </template> </up-image>Create a vertical carousel
To change the carousel orientation to vertical, set thedirectionprop tovertical. When doing so, ensure the indicator configuration also specifiesdirection: 'vertical'and a compatibleindicatorPosition(e.g.,right).<up-swiper :list="swiperList" :height="300" direction="vertical" :indicator="{ type: 'dots', direction: 'vertical', indicatorPosition: 'right' }" />Add navigation controls to Swiper-Nav
Enable navigation buttons usingshow-controls. You can handle navigation via the@prevand@nextevents, or the generic@changeevent which provides the direction and source.<up-swiper-nav :current="currentIndex" :total="5" :show-controls="true" @prev="handlePrev" @next="handleNext" />const handlePrev = () => { if (currentIndex.value > 0) currentIndex.value-- } const handleNext = () => { if (currentIndex.value < 4) currentIndex.value++ }Implement a Live Photo component using up-live-photo
Theup-live-photocomponent allows users to play a video by long-pressing a static image. It requires both a video source (video-src) and a static image source (src). For best results, ensure the video and image share the same aspect ratio.<up-live-photo video-src="https://sample-videos.com/zip/10/mp4/SampleVideo_360x240_1mb.mp4" src="https://picsum.photos/400/300?random=1" width="300" height="200" radius="12" />Implement a basic waterfall layout with up-waterfall
Theup-waterfallcomponent creates a multi-column layout where items are distributed based on their height. By default, if no slot is used, the component renders images based on the field specified inimageField(defaults toimgUrl).<template> <up-waterfall :list="waterfallList" :column="2" @item-click="handleItemClick" @load-complete="handleLoadComplete" /> </template> <script setup> import { ref } from 'vue' const waterfallList = ref([ { id: 1, imgUrl: 'https://picsum.photos/300/400?random=1', title: 'Project 1' }, { id: 2, imgUrl: 'https://picsum.photos/300/600?random=2', title: 'Project 2' } ]) function handleItemClick(item, index) { console.log('Clicked item:', item, index) } function handleLoadComplete() { console.log('Waterfall load complete') } </script>Customize content and layout in up-empty
Theup-emptycomponent provides slots to override the default image, description, or add additional content (like buttons) below the placeholder.<template> <up-empty image="error" description="加载失败"> <!-- Default slot for content below the description --> <div style="margin-top: 10px"> <button icon="refresh" type="primary">重试</button> </div> </up-empty> </template>Implement a basic list with pull-to-refresh and infinite loading
Theup-listcomponent usesv-model:list-objto bind the list state (loading, finished, refreshing, and the data array). It integrates withscroll-viewproperties to enable refreshing and scrolling. Use the@on-refreshevent for pull-to-refresh and@on-loadfor infinite scrolling.<template> <view class="h-50vh"> <up-list v-model:list-obj="result" :scroll-view-props="{ refresherEnabled: true, scrollY: true }" @on-load="onLoadMore" @on-refresh="onRefresh" > <template #default="{ data: { list } }"> <view v-for="(item, index) in list" :key="index" class="mb-4 flex"> <image :src="item.cover" class="h-20 w-20" mode="widthFix" /> <view>{{ item.title }}</view> </view> </template> </up-list> </view> </template> <script setup> // result should be an object containing { list: [], loading: boolean, finished: boolean, refreshing: boolean } const result = ref({ list: [], loading: false, finished: false, refreshing: false }); const onRefresh = () => { /* Fetch first page */ }; const onLoadMore = () => { /* Fetch next page */ }; </script>Enable dark mode in uni-ui-plus
To enable dark mode for components in
uni-ui-plus, wrap them in theup-config-providercomponent and set thethemeprop todark.Prerequisite: You must import the theme variable file in your entry file (e.g.,
App.vue) before using dark mode. The import path depends on your installation method:- For npm installation:
@use 'uni-ui-plus/styles/theme/index.scss' as *; - For uni_modules installation:
@use '@/uni_modules/uni-ui-plus/styles/theme/index.scss' as *;
<up-config-provider theme="dark"> <up-empty description="暂无数据" /> </up-config-provider>- For npm installation: