uni-app中表格分页

样式:

代码实现:

template

复制代码
<uni-table ref="table" border stripe emptyText="暂无更多数据">
	<uni-tr>
		<uni-th width="150" align="center">库位名称</uni-th>
		<uni-th width="150" align="center">库位编码</uni-th>
	</uni-tr>
	<uni-tr v-for="(item, index) in list" :key="index" @row-click="handleRowClick(item, $event)">
		<uni-td align="center">{{ item.locationName }}</uni-td>
        <uni-td align="center">{{ item.locationCode }}</uni-td>
	</uni-tr>
</uni-table>
	<view class="uni-pagination-box"><uni-pagination show-icon :page-size="pageSize"
:current="pageCurrent" :total="total" @change="change" /></view>

script

复制代码
data() {
			return {
				list: [],
				selectedIndexs: [],
                pageCurrent: 1,       // 当前页码(从1开始)
                pageSize: 10,         // 每页条数
                total: 0,             // 总条数(用于分页控件)
				loading: false,
			}
		},
// 分页触发
			change(e) {
				// this.$refs.table.clearSelection()
				// this.selectedIndexs.length = 0
				this.handleLocationCode(e.current)
			},
	
			handleLocationCode(pageIndex) {
				let data = {
					UserName: this.userInfo.UserName,
					Type: "1",
					PageIndex: pageIndex ? pageIndex : 1,
					PageSize: 10,
					MenuCode: 'UnitLoadInTask'
				};
				console.log('获取起点', data)
				GetPlainLocations(data)
					.then(res => {
						console.log('获取起点提交成功', res.data)
						
				this.list = res.data.data
			console.log(this.list)
      // ✅ 从任意一条记录中取总条数(因为每条都有 TotalNum)
     // 如果 data 为空,则 total = 0
	this.total = res.data.data.length > 0 ? res.data.data[0].TotalNum : 0;
	// 同步当前页码
	this.pageCurrent = pageIndex;
	
					})
					.catch(err => {
						console.error('请求失败:', err);
						this.list = [];
						this.total = 0;
					});

			},
相关推荐
00后程序员张7 小时前
python 抓包在实际项目中的合理位置,结合代理抓包、设备侧抓包与数据流分析
android·ios·小程序·https·uni-app·iphone·webview
吴汉三11 小时前
iOS 和 HarmonyOS 兼容笔记
uni-app
apollo_qwe14 小时前
UniApp 请求封装实战:优雅实现 Token 无感刷新(附完整代码)
uni-app
2501_9159184115 小时前
使用 HBuilder 上架 iOS 应用时常见的问题与应对方式
android·ios·小程序·https·uni-app·iphone·webview
2501_9160074716 小时前
iOS 崩溃日志的分析方法,将崩溃日志与运行过程结合分析
android·ios·小程序·https·uni-app·iphone·webview
2501_9160074717 小时前
React Native 混淆在真项目中的方式,当 JS 和原生同时暴露
javascript·react native·react.js·ios·小程序·uni-app·iphone
00后程序员张17 小时前
苹果应用商店上架App流程,签名证书、IPA 校验、上传
android·ios·小程序·https·uni-app·iphone·webview
2501_9160074717 小时前
iOS 上架需要哪些准备,围绕证书、描述文件和上传方式等关键环节展开分析
android·ios·小程序·https·uni-app·iphone·webview
2501_9151063218 小时前
iOS 上架费用解析,哪些成本可以通过流程优化降低。
android·ios·小程序·https·uni-app·iphone·webview
小离a_a19 小时前
uniapp微信小程序实现拍照加水印,水印上添加当前时间,当前地点等信息,地点逆解析使用的是高德地图
微信小程序·小程序·uni-app