问题:封装request请求,在华为v10(版本9.1.0)的微信浏览器内,无法正常发起请求,普通浏览器没问题(之前同样的封装request编译小程序同一部手机不会出现这个问题)
const httpRequestImg = (obj) => {
let httpDefaultOpts = {
url: baseUrl+obj.url,
data: obj.data,
method: obj.method,
header: {
"Content-Type": "application/x-www-form-urlencoded",
token: uni.getStorageSync('token'),
'sign':crypto.encrypt(JSON.stringify({
app_type: 'wechat-site',
version: 1,
time: new Date().getTime(),
temp: Math.random() * 100
})),
version: 1,
time: new Date().getTime(),
apptype: 'wechat-site',
},
dataType: 'json',
}
let promise = new Promise((resolve, reject)=> {
alert('进入Promise'+obj.url);
uni.request(httpDefaultOpts).then(
(res) => {
if(res[1].statusCode==401){
uni.clearStorageSync();
uni.switchTab({url:'/pages/index/index'})
return
}
if(res[1].statusCode!=200){
uni.showToast({title: '请求失败,请稍后重试',icon:'none'});
return
}
if(res[1].data.status==200){
resolve(res[1].data)
}else{
resolve(res[1].data)
uni.showToast({
title: res[1].data.message,
icon:'none'
});
}
}
).catch((response) => {
uni.showToast({title: '请求失败,请重新请求',icon:'none'});
reject(response)
}
)
})
return promise
};
0 个回复