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;
					});

			},
相关推荐
奔跑的web.15 小时前
UniApp 路由导航守
前端·javascript·uni-app
特立独行的猫a16 小时前
主要跨端开发框架对比:Flutter、RN、KMP、Uniapp、Cordova,谁是未来主流?
flutter·uni-app·uniapp·rn·kmp·kuikly
万物得其道者成1 天前
UniApp 多端滑块验证码插件 zxj-slide-verify 实用指南
uni-app
蓝帆傲亦1 天前
支付宝小程序性能暴增秘籍:UniApp项目极限优化全攻略
小程序·uni-app
2501_916008892 天前
深入解析iOS机审4.3原理与混淆实战方法
android·java·开发语言·ios·小程序·uni-app·iphone
QT.qtqtqtqtqt2 天前
uni-app小程序前端开发笔记(更新中)
前端·笔记·小程序·uni-app
喵喵虫2 天前
uniapp修改封装组件失败 styleIsolation
uni-app
游戏开发爱好者83 天前
日常开发与测试的 App 测试方法、查看设备状态、实时日志、应用数据
android·ios·小程序·https·uni-app·iphone·webview
2501_915106323 天前
app 上架过程,安装包准备、证书与描述文件管理、安装测试、上传
android·ios·小程序·https·uni-app·iphone·webview
2501_915106323 天前
使用 Sniffmaster TCP 抓包和 Wireshark 网络分析
网络协议·tcp/ip·ios·小程序·uni-app·wireshark·iphone