直接贴代码
getList(){
let that = this;
uni.request({
url: that.api_url+'resource/lists', //仅为示例,并非真实接口地址。
header: {
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
'token':that.token
},
method:'POST',
data:{
page:that.page,
},
success: (res) => {
if(res.data.code == 1){
if(that.page == 1){
var newlist = res.data.data.data;
console.log(newlist);
}else{
var newlist = JSON.parse(JSON.stringify(that.list));
newlist.push(...res.data.data.data);
}
that.list = newlist;
that.page = res.data.data.current_page+1;
}
},
});
},
前端传page参数,onload的时候page=1,请求后端接口拿到当前page然后+1,
旧的数据通过push添加新数据,再赋值给list
下面是后端代码:
$page = input('page',1,'intval');
$list = ResourcesModel::order('status desc,id desc')->paginate(10);
$this->success('success',$list);
发表评论 取消回复