1,首先写好需要的参数
//接口所需要的参数
QueryParams:{
query:"",
cid:"",
pagenum:1,
pagesize:10
},
//总页数
totalPages:1,
2,在index.js中写需要拿到的数据
//先获取相对应接口数据需要的东西并且进行计算,存放渲染
async getgoodslist(){
//封装的接口request.js使用异步操作
const res=await request({url:"/goods/search",data:this.QueryParams})
//通过log查询到对应名
console.log(res);
// 获取总条数
const total=res.total;
// 计算总页数
this.totalPages=Math.ceil(total/this.QueryParams.pagesize);
console.log(this.totalPages);
this.setData({
//这里的goodsList是点进商品列表传进来的所有数据
// 拼接了数组
goodsList:[...this.data.goodsList,...res.goods]
})
},
3,写上滑事件
// 页面上滑 滚动条触底事件
onReachBottom(){
// 1 判断还有没有下一页数据
if(this.QueryParams.pagenum>=this.totalPages){
// 没有下一页数据
wx.showToast({ title: