getHotCity(){
//设置加载效果 wx.showLoading
wx.showLoading({
title:"拼命加载中...",
mask:true,//是否显示触摸蒙版,禁止穿透
success:()=>{}
})
//网络请求API
wx.request({
url: 'https://elm.cangdu.org/v1/cities?type=hot',
method:"GET",
header:{
"content-type":"json"
},
success:(res)=>{
console.log(res)
this.setData({
hotCity:res.data,
})
},
fail:()=>{},
complete:()=>{
//关闭加载效果
wx.hideLoading({
success: (res) => {},
})
},
})
},
事件一开始就执行加载效果:wx.showLoading({}),title是加载显示的文本;mask是是否添加防触摸蒙版
然后在函数相应结束后的complete中,使用wx.hideLoading({ success: (res) => {},});
关闭加载效果就可以了