网站首页 > 教程文章 正文
前情提示
vue2
hubilderx4.29最新版本
mescroll-uni-1.3.8目前最新版本
使用mescroll-body支持原生组件,性能更好,非常容易接入,官方也提供了很多demo示例。
快速安装
使用uni_modules直接下载导入。不需要配置其他任何地方,不需要配置不必配置pages.json。
业务接口示例
返回要有总页码、或者总条数,这里用的总条数
{
"success": true,
"message": "",
"code": 200,
"result": {
"records": [
{
"id": "1849444662765731841",
"fatteningPigNo": "333",
"filingDate": null,
"plantName": null,
"buildingName": null,
"fieldName": null,
"frailWeight": null,
"whetherManual": null,
"responsiblePersonnel": null,
"createTime": "2024-10-24 21:35:43",
"createBy": "admin",
"updateTime": null,
"updateBy": null,
"delFlag": 0,
"sysOrgCode": "A01",
"tenantId": null
},
{
"id": "1849450786642509825",
"fatteningPigNo": "请问请问",
"filingDate": null,
"plantName": null,
"buildingName": null,
"fieldName": null,
"frailWeight": null,
"whetherManual": null,
"responsiblePersonnel": null,
"createTime": "2024-10-24 22:00:03",
"createBy": "admin",
"updateTime": null,
"updateBy": null,
"delFlag": 0,
"sysOrgCode": "A01",
"tenantId": null
}
],
"total": 2,
"size": 10,
"current": 1,
"orders": [
],
"optimizeCountSql": true,
"searchCount": true,
"maxLimit": null,
"countId": null,
"pages": 1
},
"timestamp": 1729778822564
}
效果图
业务界面代码
如果你引入了uview,基本可以完全复制使用
<template>
<view>
<!--标题和返回-->
<cu-custom :bgColor="NavBarColor" isBack>
<block slot="backText">返回</block>
<block slot="content">育肥猪信息</block>
</cu-custom>
<view class="search">
<u-search v-model="keywords" @custom="search" @search="search"></u-search>
</view>
<!--滚动加载列表-->
<view class="btn-plus" @click="navTo('pdtjPigYfInfoForm')">
<u-icon name="plus-circle-fill" size="90" color="#3d87ff"></u-icon>
</view>
<mescroll-body ref="mescrollRef" top="105rpx" @init="mescrollInit" :up="upOption" :down="downOption"
@down="downCallback" @up="upCallback">
<u-cell-group class="list" :border="false">
<u-swipe-action :options="options2" v-for="(item, index) in list" :key="item.id" :index="index"
@click="optionsClick">
<u-cell-item :arrow="true" @click="navTo('pdtjPigYfInfoForm?id='+item.id)">
<text slot="title">{{item.name || item.id}}</text>
<text slot="label">创建者:{{item.createBy}} | 时间:{{item.createTime}}</text>
</u-cell-item>
</u-swipe-action>
</u-cell-group>
</mescroll-body>
</view>
</template>
<script>
import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
import Mixin from "@/common/mixin/Mixin.js";
export default {
mixins: [MescrollMixin, Mixin],
data() {
return {
keywords: '',
CustomBar: this.CustomBar,
NavBarColor: this.NavBarColor,
purl: "/pball/pdtjPigYfInfo/list",
options2: [{
text: '收藏',
style: {
backgroundColor: '#3c9cff'
}
}, {
text: '删除',
style: {
backgroundColor: '#f56c6c'
}
}]
};
},
methods: {
goHome() {
this.$Router.push({
name: "index"
})
},
search(value) {
console.log('search', value)
},
optionsClick(rowIndex, btnIndex) {
},
navTo(url) {
uni.navigateTo({
url: url
});
}
}
}
</script>
<style lang="scss">
</style>
@/common/mixin/Mixin.js主要用了请求业务接口,和配置mescroll的options。
/**
* Copyright (c) 2013-Now http://pusdn.com All rights reserved.
* Author: PGZ Club
*/
const ListMixin = {
data() {
return {
downOption: {
auto: false, //是否在初始化完毕之后自动执行下拉回调callback; 默认true
},
upOption: {
page: {
num: 0,
size: 10,
time: null
},
noMoreSize: 1, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
empty: {
tip: '~ 暂无更多数据 ~', // 提示
// btnText: '返回首页'
},
textNoMore: '-- 暂无更多数据 --',
toTop: {
src: null,
offset: 1000,
duration: 300,
zIndex: 9990,
right: "50rpx",
bottom: "165rpx",
safearea: false,
width: "40px",
radius: "50%",
left: null
}
},
queryParam: {
pageNo: 1,
pageSize: 10
},
list: [],
pageNo: 1,
pageSize: 10,
}
},
onShow() {
this.canReset && this.mescroll.resetUpScroll()
this.canReset && this.mescroll.scrollTo(0, 0)
this.canReset = true
},
methods: {
/*下拉刷新的回调 */
downCallback() {
//加载列表数据
this.loadList('down');
},
/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
upCallback(page) {
let param = this.queryParam
param.pageNo = page.num,
param.pageSize = page.size
if (page.num == 1) {
this.list = [];
}
console.log("upCallback==param::", param)
this.$http.get(this.purl, {
params: param
}).then(res => {
console.log("upCallback请求返回res", res)
if (res.data.success) {
let rec = res.data.result.records;
let totalSize = res.data.result.total;
let hasNext = true;
if (!rec || rec.length < this.pageSize) {
console.log("加载完成!没有更多了")
hasNext = false;
}
console.log("hasNext", hasNext)
//方法四 (不推荐),会存在一个小问题:比如列表共有20条数据,每页加载10条,共2页.如果只根据当前页的数据个数判断,则需翻到第三页才会知道无更多数据.
// this.mescroll.endSuccess(rec.length);
this.mescroll.endBySize(rec.length, totalSize);
//设置列表数据
this.list = this.list.concat(rec);
this.$forceUpdate();
} else {
this.mescroll.endErr();
}
}).catch(() => {
//加载失败, 结束
this.mescroll.endErr();
})
},
loadList(flag) {
let param = this.queryParam
param.pageNo = this.pageNo,
param.pageSize = this.pageSize
console.log("请求参数", param)
if (flag == 'down') {
if (this.mescroll.optUp.use) {
this.mescroll.resetUpScroll()
} else {
setTimeout(() => {
this.mescroll.endSuccess();
}, 500)
}
}
return false;
this.$http.get(this.purl, {
params: param
}).then(res => {
if (res.data.success) {
console.log("请求返回res.data", res.data)
let rec = res.data.result.records
if (flag == 'down') {
//下拉刷新成功的回调,隐藏下拉刷新的状态
// this.mescroll.endSuccess();
// if(this.mescroll.optUp.use){
// this.mescroll.resetUpScroll()
// }else{
// setTimeout(()=>{
// this.mescroll.endSuccess();
// }, 500)
// }
}
//添加新数据
this.list = rec;
/* if(!rec || rec.length<this.pageSize){
console.log("加载完成!")
} */
} else {
console.log("请求返回else", res)
this.mescroll.endErr();
}
}).catch((err) => {
console.log("请求返回err", err)
//加载失败, 结束
this.mescroll.endErr();
})
},
}
}
export default ListMixin;
猜你喜欢
- 2024-12-29 vue前端埋点 - 神策埋点 vue前端埋点怎么实现
- 2024-12-29 面试遇到 性能优化 必答的 9 个点,加分!
- 2024-12-29 Vue NextTick揭秘:你不知道的秘密!
- 2024-12-29 史上最全 vue-router 讲解 !!! vue-router怎么用
- 2024-12-29 前端项目重构的一些思考和复盘 前端项目构建工具有什么
- 2024-12-29 vue3.0系列:Vue3自定义PC端弹窗组件V3Layer
- 2024-12-29 VueUse中的这5个函数,也太好用了吧
- 2024-12-29 vue-cms开源企业级后台管理系统 开源vue项目
- 2024-12-29 Vue和React的一些对比:哪个更适合你?
- 2024-12-29 第14天|14天搞定Vue3.0,电子地图,一定要用Vue?
- 06-18CentOS7安装Mongodb 4.x.x(centos7安装openstack)
- 06-18Window环境配置Mongodb(mongodb默认配置文件路径)
- 06-18FineReport如何连接和使用MongoDB数据库
- 06-18nosql之mongodb(nosql怎么读正确发音)
- 06-18Mongodb centos7安装(mongodb4.4.2安装教程)
- 06-18群晖(Synology)NAS 安装 MongoDB(群晖安装nat123)
- 06-18MongoDB 安装及实践(mongodb的安装过程和操作命令)
- 06-18MongoDB最全详解(万字图文总结)(mongodb lsm)
- 最近发表
-
- CentOS7安装Mongodb 4.x.x(centos7安装openstack)
- Window环境配置Mongodb(mongodb默认配置文件路径)
- FineReport如何连接和使用MongoDB数据库
- nosql之mongodb(nosql怎么读正确发音)
- Mongodb centos7安装(mongodb4.4.2安装教程)
- 群晖(Synology)NAS 安装 MongoDB(群晖安装nat123)
- MongoDB 安装及实践(mongodb的安装过程和操作命令)
- MongoDB最全详解(万字图文总结)(mongodb lsm)
- CentOS安装MongoDB教程(centos安装mpich)
- MongoDB入门指南:下载、安装和配置一款强大的NoSQL数据库
- 标签列表
-
- location.href (44)
- document.ready (36)
- git checkout -b (34)
- 跃点数 (35)
- 阿里云镜像地址 (33)
- qt qmessagebox (36)
- mybatis plus page (35)
- vue @scroll (38)
- 堆栈区别 (33)
- 什么是容器 (33)
- sha1 md5 (33)
- navicat导出数据 (34)
- 阿里云acp考试 (33)
- 阿里云 nacos (34)
- redhat官网下载镜像 (36)
- srs服务器 (33)
- pico开发者 (33)
- https的端口号 (34)
- vscode更改主题 (35)
- 阿里云资源池 (34)
- os.path.join (33)
- redis aof rdb 区别 (33)
- 302跳转 (33)
- http method (35)
- js array splice (33)