vue 移动端加载更多分页组件_Vue移动端上拉加载更多实现请求分页数据

本文介绍了一个Vue移动端应用中实现加载更多分页数据的组件。通过在`mounted`钩子中初始调用获取数据的方法,并在`methods`中定义`getWithdrawalList`用于加载更多数据。当数据加载完毕时,状态会更新为'没有更多了~'。此外,还提供了`loadMore`方法供用户触发加载更多操作。
摘要由CSDN通过智能技术生成
{{item}}
{{ loadTxt[loadKey] }}

name:'App4',

components: {

},

data() {return{

page:1,//当前页

total: 0,//总数据数量

pageSize: 10,//每页几个

loadTxt: {

more:"正在加载...",

none:"没有更多了~",

err:"加载失败~"},

loadKey:"none",

datalist: [],//数据列表

loading: false,

dataMax:0};

},

mounted() {this.getWithdrawalList();//一进入页面就调用获取数据的方法

},

methods: {

getWithdrawalList() {

console.log("进入getWithdrawalList");var _this = this;this.loadKey = "more";//把展示改为"正在加载..."

//调用获取数据的接口,这里是用封装的axios

//record({

//"pageIndex": _this.page,

//"pageSize": _this.pageSize

//}).then(res => {

//if (res.data.code == 200) {

//var info = res.data.content || null;

//if (info) {

//_this.total = info.count;

//var data = info.list || [];

//_this.datalist = _this.datalist.concat(data);

//if (_this.total == _this.datalist.length) {

//_this.loadKey = "none";

//}

//} else {

//_this.loadKey = "err";

//}

//}

//});

setTimeout(function(){for(let j=_this.dataMax, len = 10; j

_this.datalist.push(j)

}

_this.dataMax+=10;

_this.total= 32;if (_this.total < _this.datalist.length) {//这里我假设数据加载完了

_this.loadKey = "none";this.loading = true}//console.log(_this.total);

//_this.loadKey = "none";

},1000);

},

loadMore() {

console.log("进入loadMore 要在手机上才有效果");

let page= this.page;

let size= this.pageSize;

let total= this.total;

let length= this.datalist.length;

let num= page *size;if (num < total && num ===length) {

console.log("loadMore......1111");++this.page;this.getWithdrawalList();

}

},

}

}

width:100%;

background-color: #f6f6f6;

padding:0.5rem 1rem 1rem;

}

.list{

width:100%;

height:2.5rem;

border: 1px solid #ccc;

margin-bottom: 0.5rem;

display: flex;

justify-content: center;

align-items: center;

}

.l-load {

text-align: center;

font-size: 0.625rem;

color: #aaa;

margin-top: 1rem;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值