uniapp在H5使用uni.request请求报错{"errMsg":"request:fail"}
try {
const [error, response] = await new Promise((resolve) => {
uni.request({
url: http://47.96.7.237:30018/?method=userquery&openid=${this.openid}
,
method: 'GET',
header: {
'Content-Type': 'application/json'
},
success: (res) => {
resolve([null, res]);
},
fail: (err) => {
resolve([err, null]);
}
});
});
if (error) {
console.error('请求失败:', error);
this.userInfoError = '请求失败,请稍后重试: ' + JSON.stringify(error);
this.bindStatus = 'unbound';
return;
}
console.log('响应数据:', response);
alert(response.data.msg);
if (response.data && response.data.msg === 'ok' && response.data.result) {
this.userInfo = {
name: response.data.result.name || '',
idno: response.data.result.idno || '',
tel: response.data.result.tel || ''
};
if (response.data.result.name && response.data.result.idno && response.data.result.tel) {
this.bindStatus = 'bound';
} else {
this.bindStatus = 'unbound';
}
} else {
this.bindStatus = 'unbound';
this.userInfoError = response.data && response.data.error ?
response.data.error :
'未查询到用户信息';
}
} catch (error) {
console.error('查询用户信息失败:', error);
this.userInfoError = '查询失败,请稍后重试: ' + error.message;
this.bindStatus = 'unbound';
} finally {
this.loading = false;
}