z-paging Documentation

repository·main·Indexed 23 days ago

https://github.com/smilezxlee/uni-z-paging

A high-performance paging component for uni-app (version 2.8.8) that automates pagination, pull-to-refresh, and infinite scrolling. It utilizes wxs and renderjs for view-layer performance and supports virtual lists for massive datasets. Compatible with Vue 2/3, JS/TS, and multiple platforms including H5, App, HarmonyOS Next, and various mini-programs. Includes specialized versions like z-paging-x for uni-app x and a companion z-tabs component for tab bar implementation.

Tokens
4.8K
Snippets
5
Records
22
Agent score
80%

What's inside z-paging

  1. Overview of z-paging

    main

    z-paging is a high-performance paging component for uni-app that simplifies implementing pull-to-refresh and load-more functionality. It is designed to be low-coupling and low-intrusion, meaning it manages pagination logic internally so you don't have to define pagination variables in your component's data or handle complex logic in your page code.

    Key Features:

    • Simple Configuration: Complete pull-to-refresh and load-more functionality can be achieved in just two steps: binding a network request method and binding the pagination result array.
    • High Performance: Uses wxs + renderjs on platforms like App-Vue, H5, WeChat Mini Program, and QQ Mini Program to implement pull-to-refresh in the view layer. It also supports virtual lists for smooth rendering of massive datasets (up to millions of rows).
    • Flexible Layouts: Supports custom pull-to-refresh/load-more effects, full-screen layouts, or being placed inside arbitrary containers. It also supports internal scroll-view scrolling and page scrolling.
    • Rich Functionality: Includes support for internationalization, automatic empty data state management, theme switching, local pagination, chat-style pagination (no flicker), sticky headers, and 'pull-to-enter second floor' effects.
    • Cross-Platform: Compatible with Vue & nvue, Vue 2 & Vue 3, JS & TS, and supports H5, App, HarmonyOS Next, and various mini-programs.
  2. Overview of z-paging features

    main

    z-paging is a high-performance paging component designed for uni-app and cross-platform development. Key capabilities include:

    • Automatic Pagination: Effortlessly implement pull-down refresh and pull-up load more by binding a network request method and a paginated result array. It handles all pagination logic and variables internally.
    • High Performance: Utilizes wxs + renderjs at the view layer for smooth pull-down refresh on App-Vue, H5, WeChat, and QQ Mini Programs. It also supports virtual lists for rendering millions of items.
    • Cross-Platform Support: Compatible with Vue & nvue, Vue2 & Vue3, JS & TS, H5, App, HarmonyOS Next, and all major mini-program platforms.
    • Flexible Layouts: Supports full-screen layouts or placement inside any container. It also features sticky headers, chat history mode, and custom empty-data views.
  3. Install z-tabs via uni_modules or npm

    main

    You can install z-tabs using two methods:

    Use HBuilderX to import the plugin directly from the DCloud plugin market.

    Method 2: npm

    1. Initialize npm if you haven't already:
      npm init -y
    2. Install the package:
      npm install @zxlee/z-tabs --save
    3. Update the package if needed:
      npm update @zxlee/z-tabs
    4. Required Configuration: If using npm, you must configure easycom in your pages.json to ensure components are resolved correctly:
      "easycom": {
          "^z-tabs": "@zxlee/z-tabs/components/z-tabs/z-tabs.vue"
      }
    npm install @zxlee/z-tabs --save
  4. Install z-tabs

    main

    You can install z-tabs using two methods:

    Use the DCloud plugin market and click [使用HbuilderX导入插件] (Import plugin via HBuilderX) in the top right corner.

    Method 2: via npm

    1. Initialize npm if you haven't already:
      npm init -y
    2. Install the package:
      npm install @zxlee/z-tabs --save
    3. Configure easycom in your pages.json to enable automatic component recognition:
      "easycom": {
          "^z-tabs": "@zxlee/z-tabs/components/z-tabs/z-tabs.vue"
      }
    npm install @zxlee/z-tabs --save
  5. How to link z-tabs with a Swiper component

    main

    To synchronize the z-tabs bottom indicator (dot/bar) with a swiper component, you must use the setDx and unlockDx methods. This ensures the slider moves smoothly during the swiper transition.

    1. Listen to the swiper's @transition event and pass e.detail.dx to tabs.setDx().
    2. Listen to the swiper's @animationfinish event to update the current index and call tabs.unlockDx().
    <template>
      <z-tabs ref="tabs" :list="tabList" :current="current" @change="tabsChange" />
      <swiper :current="current" @transition="swiperTransition" @animationfinish="swiperAnimationfinish">
        <swiper-item class="swiper-item" v-for="(item, index) in tabList" :key="index">
          xxx
        </swiper-item>
      </swiper>
    </template>
    
    <script>
    	export default {
    		data() {
    			return {
    				tabList: ['测试1','测试2','测试3','测试4'],
    				current: 0,
    			};
    		},
    		methods: {
    			// tabs notifies swiper to switch
    			tabsChange(index) {
    				this.current = index;
    			},
    			// During swiper sliding
    			swiperTransition(e) {
    				this.$refs.tabs.setDx(e.detail.dx);
    			},
    			// When swiper sliding finishes
    			swiperAnimationfinish(e) {
    				this.current = e.detail.current;
    				this.$refs.tabs.unlockDx();
    			}
    		}
    	}
    </script>
    <template>
      <z-tabs ref="tabs" :list="tabList" :current="current" @change="tabsChange" />
      <swiper :current="current" @transition="swiperTransition" @animationfinish="swiperAnimationfinish">
        <swiper-item class="swiper-item" v-for="(item, index) in tabList" :key="index">
          xxx
        </swiper-item>
      </swiper>
    </template>
    
    <script>
    	export default {
    		data() {
    			return {
    				tabList: ['测试1','测试2','测试3','测试4'],
    				current: 0, // tabs组件的current值,表示当前活动的tab选项
    			};
    		},
    		methods: {
    			//tabs通知swiper切换
    			tabsChange(index) {
    				this.current = index;
    			},
    			//swiper滑动中
    			swiperTransition(e) {
    				this.$refs.tabs.setDx(e.detail.dx);
    			},
    			//swiper滑动结束
    			swiperAnimationfinish(e) {
    				this.current = e.detail.current;
    				this.$refs.tabs.unlockDx();
    			}
    		}
    	}
    </script>
  6. Sync z-tabs with a swiper component

    main

    To create a seamless sliding experience where the tab bar indicator (dot/bar) moves in sync with a swiper component, follow this pattern:

    1. Use setDx inside the swiper's @transition event to update the indicator position during the slide.
    2. Use unlockDx inside the swiper's @animationfinish event to release the lock.
    3. Update the current index in both components to keep them in sync.

    Note: bar-animate-mode (set to worm or line) is only effective when using this sync pattern.

    <template>
      <z-tabs ref="tabs" :list="tabList" :current="current" @change="tabsChange" />
      <swiper :current="current" @transition="swiperTransition" @animationfinish="swiperAnimationfinish">
        <swiper-item class="swiper-item" v-for="(item, index) in tabList" :key="index">
          xxx
        </swiper-item>
      </swiper>
    </template>
    
    <script>
    	export default {
    		data() {
    			return {
    				tabList: ['测试1','测试2','测试3','测试4'],
    				current: 0,
    			};
    		},
    		methods: {
    			tabsChange(index) {
    				this.current = index;
    			},
    			swiperTransition(e) {
    				this.$refs.tabs.setDx(e.detail.dx);
    			},
    			swiperAnimationfinish(e) {
    				this.current = e.detail.current;
    				this.$refs.tabs.unlockDx();
    			}
    		}
    	}
    </script>
  7. Install z-paging

    main

    You can integrate z-paging into your project using one of the following methods:

    1. uni_modules (Recommended): Copy the z-paging source code folder directly into your project's uni_modules folder.
    2. Component Directory: Copy the sub-components from the z-paging folder into your project's components directory.
    3. NPM: You can also install it via npm (as indicated by the project badges).

    Note: If you are updating an existing installation, always check the Version Differences documentation first.

  8. Get started with z-paging

    main

    To use z-paging, you can explore the official documentation or download demo projects to see different implementation styles.

    Official Resources:

    Demo Downloads:

    • Vue 2 & Vue 3 (Options API): Available via the official website (use 'Import example project with HBuilderX' or 'Download ZIP').
    • Vue 3 (Composition API): Available on the GitHub repository.
  9. Install and integrate z-paging

    main

    You can integrate z-paging into your uni-app project using one of the following methods:

    1. uni_modules (Recommended): Copy the z-paging source folder directly into your project's uni_modules folder.
    2. Components folder: Copy the sub-components into your project's components directory.
    3. DCloud Plugin Market: Access and install via the DCloud Plugin Market.

    For existing users, always check the Upgrade Guide before updating to a new version to handle breaking changes.