getDate(){
wx.showLoading({
title: '加载中',
});
wx.request({
url: 'test.php', //仅为示例,并非真实的接口地址
data: {},
header: {
'content-type': 'application/json' // 默认值
},
success (res) {
wx.showToast({
title: '请求成功',
icon: 'success'
})
},
fail(res){
wx.showToast({
title:res.data.message,
icon: 'none'
})
})
},
compelet(){
wx.hideLoading();
}
})
}
上面操作的话,wx.hideLoading()之后wx.showToast()就无法触发。wx.showToast()本身就有wx.hideLoading()的属性,wx.showToast()显示的时候,即使没调用wx.hideLoading()方法,上面的wx.showLoading({title:'加载中'})也会消失。
getDate(){
wx.showLoading({
title: '加载中',
});
wx.request({
url: 'test.php', //仅为示例,并非真实的接口地址
data: {},
header: {
'content-type': 'application/json' // 默认值
},
success (res) {
if(如果有toast提示){
wx.showToast({
title: '提示内容',
icon: 'success'
})
}else{
wx.hideLoading()
}
},
fail(res){
wx.showToast({
title: res.data.message,
icon: 'none'
})
})
},
compelet(){
}
})
}