news 2026/7/31 18:20:51

uniapp 好用的分页z-paging组件基本用法

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
uniapp 好用的分页z-paging组件基本用法

官网文档:z-paging。

该组件可以实现下拉刷新上拉分页加载数据返回顶部等功能。

使用该组件前,需要注意的地方。

  • z-paging默认铺满全屏,此时页面所有view都应放在z-paging标签内,否则会被盖住
  • 处理分页时,@query所绑定的方法不要自己调用!!需要刷新列表数据时,只需要调用paging.value.reload()即可。

下拉刷新区带有图片,要引用组件custom-refresher.vue。下拉刷新的动图gif,可以到 icons8 下载素材。

<!-- z-paging自定义的下拉刷新view --> <template> <view class="refresher-container"> <!-- 这里的图片请换成自己项目的图片 --> <image class="refresher-image" mode="aspectFit" src="@/static/refresher_loading.gif"></image> <text class="refresher-text">{{statusText}}</text> </view> </template> <script> export default { data() { return { }; }, computed: { statusText() { // 这里可以做i18n国际化相关操作,可以通过uni.getLocale()获取当前语言(具体操作见i18n-demo.vue); // 获取到当前语言之后,就可以自定义不同语言下的展示内容了 const statusTextArr = ['哎呀,用点力继续下拉!', '拉疼我啦,松手刷新~~', '正在努力刷新中...', '刷新成功啦~']; return statusTextArr[this.status]; } }, props: { status: { type: Number, default: function() { return 0; }, }, } } </script> <style scoped> .refresher-container { /* #ifndef APP-NVUE */ display: flex; /* #endif */ height: 150rpx; flex-direction: column; align-items: center; justify-content: center; } .refresher-image { margin-top: 10rpx; height: 45px; width: 45px; } .refresher-text { margin-top: 10rpx; font-size: 24rpx; color: #666666; } </style>

index.vuetemplate页代码:

<template> <view class="wrap"> <!-- 分页组件的引用 --> <z-paging ref="paging" v-model="data.order_list" loading-more-no-more-text="我也是有底线的!" :auto-show-back-to-top="true" :back-to-top-style = "{right:'60rpx'}" @query="queryList" > <template #refresher = "{refresherStatus}"> <custom-refresher :status="refresherStatus"></custom-refresher> </template> <!-- 滑动时置顶固定的内容 --> <up-sticky bgColor="#fff"> <view class="search"> <up-search placeholder="请输入手机号" shape="round" inputAlign="center" height="36" borderColor="#1aad1a" :clearabled="true" v-model="data.search_phone" :show-action="false" @clear="clearSearchValue" @search="searchPhone"> </up-search> </view> <view class="tabs"> <up-tabs :list="tabs_list" @click="tabclickFun" lineWidth="30" lineColor="#1aad1a" :activeStyle="{ color: '#303133', fontWeight: 'bold', transform: 'scale(1.05)' }" :inactiveStyle="{ color: '#606266', transform: 'scale(1)' }" itemStyle="padding-left: 15px; padding-right: 15px; height: 34px;" > </up-tabs> </view> <view class="num"> 总共:<text class="text">{{data.total}}</text> </view> </up-sticky> <!-- 列表显示 --> <view class="content"> <view class="li" v-for="(item,index) in data.order_list" :key="index"> <view class="img"> <image class="image" :src="spellImgUrlComputed(item?.pics?.url?.[0])" mode="aspectFill" :lazy-load="true"/> </view> <view class="right"> <view class="label"> <view class="name">{{ item?.uname }}</view> <view class="role">{{ item?.juese }}</view> <view class="status"> <up-text prefixIcon="tags-fill" :iconStyle="{color:'#ffca28'}" size="12" type="primary" text="未结案" v-if="item?.isfinish == 0"></up-text> <up-text prefixIcon="tags-fill" :iconStyle="{color:'#ffca28'}" size="12" type="error" text="已结案" v-else></up-text> </view> </view> <view class="btns"> <up-button type="success" size="small" icon="eye" text="查看"></up-button> <up-button type="primary" size="small" icon="skip-forward-right" text="跟进" @click="openGJJLFun(item.id,item.uname)"></up-button> </view> </view> </view> </view> </z-paging> </view> </template>

index.vuescript页代码:

<script setup lang="ts">

import { ref,reactive } from 'vue';

import { onLoad } from '@dcloudio/uni-app';

import {allOrderlistApi} from '@/service/customerApi'

import customRefresher from '@/components/custom-refresher/custom-refresher.vue'

const data = ref({

search_phone:'',

cur_status:0,

total:0,

order_list:[] //数据列表

})

const paging = ref()

const tabs_list = reactive([

{ value:0,name: '全部' },

{ value:1,name: '未跟进' },

{ value:2,name: '已跟进' },

{ value:3,name: '未分配' },

{ value:4,name: '已结案' },

{ value:5,name: '已退回' },

]);

// 根据手机号搜索订单

const searchPhone = ()=> {

// 手机正则校验

paging.value.reload()//刷新列表数据

}

const clearSearchValue = ()=> {

data.value.search_phone = ''

paging.value.reload()//刷新列表数据

}

// 切换tabs选项卡

function tabclickFun(item:any) {

console.log('tabclickFun', item);

data.value.cur_status = item.value;

paging.value.reload()//刷新列表数据

}

// 处理分页

// @query所绑定的方法不要自己调用!!需要刷新列表数据时,只需要调用paging.value.reload()即可

constqueryList= async (pageNo:number, pageSize:number) => {

uni.showLoading({

title: '加载中...',

mask: true, // 是否显示透明蒙层,防止触摸穿透

});

let params = {

index:data.value.cur_status,

page:pageNo, //默认是1

size:pageSize, //默认是10

phone:data.value.search_phone

}

let res:any = await allOrderlistApi(params)//发起请求

console.log('渲染数据',res);

uni.hideLoading();

if(res.code == 1){

data.value.total = res.total

let data_ = res.data.map((item:any,index:number) => {

if(item.pics != ''){

res.data[index].pics = JSON.parse(item.pics)

}

return item;

});

paging.value.complete(data_)

}else{

paging.value.complete(null)

}

}

// 图片补充长链接

function spellImgUrlComputed(value:any){

if(value){

let baseurl = 'https://xxx.xx.cc'

return /^http/.test(value) ? value : baseurl+value

}else{

return 'https://xxx.xxx.cc/static/picture/img_null.png'; // 没有图片,默认显示一个空图代替显示

}

}

</script>

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/7/31 18:20:33

FFmpegFreeUI:Windows上最强大的视频转码图形界面工具终极指南

FFmpegFreeUI&#xff1a;Windows上最强大的视频转码图形界面工具终极指南 【免费下载链接】FFmpegFreeUI 3FUI 是 ffmpeg 在 Windows 上的轻度专业交互外壳&#xff0c;收录大量参数&#xff0c;界面美观&#xff0c;交互友好。此项目面向国内使用环境&#xff0c;让普通人也能…

作者头像 李华
网站建设 2026/7/31 18:19:41

第四章概念知识工程

第五章语言结构组织工程5.1 Sentence Organization Engine&#xff08;语句组织引擎&#xff09;语言表达不是简单的词语排列&#xff0c;而是由多个语言元素按照一定结构关系组织形成。WSaiOS认为&#xff1a;一个完整语句的形成&#xff0c;需要经过对象确定、关系确定、结构…

作者头像 李华
网站建设 2026/7/31 18:17:51

3分钟搞定B站视频备份:m4s-converter完整使用指南

3分钟搞定B站视频备份&#xff1a;m4s-converter完整使用指南 【免费下载链接】m4s-converter 一个跨平台小工具&#xff0c;将bilibili缓存的m4s格式音视频文件合并成mp4 项目地址: https://gitcode.com/gh_mirrors/m4/m4s-converter 你是否曾经遇到过收藏的B站视频突然…

作者头像 李华
网站建设 2026/7/31 18:14:15

智能资金概念量化分析:用Python掌握市场主力动向的终极指南

智能资金概念量化分析&#xff1a;用Python掌握市场主力动向的终极指南 【免费下载链接】smartmoneyconcepts Discover our Python package designed for algorithmic trading. It brings ICTs smart money concepts to Python, offering a range of indicators for your algor…

作者头像 李华
网站建设 2026/7/31 18:13:54

如何用Python智能资金分析工具提前发现市场趋势转折点

如何用Python智能资金分析工具提前发现市场趋势转折点 【免费下载链接】smartmoneyconcepts Discover our Python package designed for algorithmic trading. It brings ICTs smart money concepts to Python, offering a range of indicators for your algorithmic trading s…

作者头像 李华