真机测试发现调用 showToast 不显示,或者闪一下就没了。
可能是与 wx.showLoading 冲突了,两者调用的是同个框。
封装请求时,hideLoading不要写在complete里。
export const get = (url, data, callback) => {
uni.showLoading({
title:'加载中'
})
uni.request({
url: url,
header: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded', //自定义请求头信息
'ACCESS-TOKEN':token,//token
},
data: data,
timeout: 10000,
method: 'GET',
success: (response) => {
uni.hideLoading();
callback(response.data);
},
fail: (error) => {
uni.hideLoading();
if (error && error.message) {
uni.showToast({
title: error.message,
icon:'none',
duration: 2000
});
}
},
complete: () => {
// uni.hideLoading();
}
});
}