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

			},
相关推荐
anyup6 小时前
分享 5 套 uni-app 实用主题,一键适配暗黑模式
前端·uni-app·视觉设计
gg1593572846010 小时前
Uni-app跨平台开发全解课程:从零基础到企业级多端落地实战
vue.js·uni-app
xshirleyl2 天前
uniapp小兔鲜儿day3
uni-app
Geek_Vison2 天前
2026 跨端框架横评:FinClip、Taro、uni-app、Remax、mPaaS 五款工具技术+业务双维度测评
小程序·uni-app·taro·mpaas·小程序容器
RuoyiOffice2 天前
从 0 到 1 搭建 RuoyiOffice:30 分钟跑通后端+前端+移动端
前端·spring boot·uni-app·开源·oa·ruoyioffice·hrm
Geek_Vison2 天前
APP集成了50多个小程序后,如何搭建一个小程序管理平台来管理这些小程序~
小程序·uni-app·apache·mpaas·小程序容器
梦曦i3 天前
uni-router v1.1.1发布:守卫超时保护+路由监听
前端·uni-app
梦曦i3 天前
全面解析uni-router v1.2.0功能
前端·uni-app
不如摸鱼去3 天前
Wot UI 2.1.0 发布:ConfigProvider 全局配置能力升级
ui·小程序·uni-app
PedroQue993 天前
uni-router:uni-app路由管理新选择
前端·uni-app