在上拉触底的时候如何添加小程序的loading效果呢??就是左边现实的效果。有一个转动的圈圈
首先我们打开.js文件
在原有的请求颜色的基础上添加wx.showLoading
getColors(){
wx.showLoading({
title: '数据加载中....',
})
wx.request({ //这个是上一节的内容
url: 'https://www.escook.cn/api/color',
method:'GET',
success:({ data:res}) =>{
this.setData({
colorList:[...this.data.colorList,...res.data]
})
}, //到这里都是
complete:()=>{
wx.hideLoading()
}
})
},
使用wx.showLoading({})函数,title就是圈圈下面的文字。
但是问题来了如果只是用showLoading函数的话会导致一个问题,就是一旦开启它便无法关闭。
所以我们需要添加wx.hideLoading()函数来关闭
complete:()=>{
wx.hideLoading()