我正在使用axios
在React native中将一些数据发布到服务器,但是我遇到了一个问题,我的代码在IOS中运行良好,但是我在android情况下遇到了一些问题。这是我的代码,看看吧。
login = () => {
const { username, password } = this.state;
let reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (username == "") {
//alert("Please enter Email address");
this.setState({ email: "Please enter Email address" });
} else if (reg.test(username) === false) {
//alert("Email is Not Correct");
this.setState({ email: "Email is Not Correct" });
return false;
} else if (password == "") {
this.setState({ email: "Please enter password" });
} else {
this.openProgressbar();
axios
.post(
CONSTANT.BaseUrl + "user/do-login",
{
email: username,
password: password
}
)
.then(async (response) => {
if (response.data.type == "success") {
await AsyncStorage.setItem(
"full_name",
response.data.profile.pmeta.full_name
);
await AsyncStorage.setItem(
"user_type",
response.data.profile.pmeta.user_type
);
await AsyncStorage.setItem(
"profile_img",
response.data.profile.pmeta.profile_img
);
await AsyncStorage.setItem(
"profileBanner",
response.data.profile.pmeta.banner_img
);
await AsyncStorage.setItem(
"profileType",
response.data.type
);
await AsyncStorage.setItem(
"projectUid",
response.data.profile.umeta.id
);
await AsyncStorage.setItem(
"projectProfileId",
JSON.stringify(response.data.profile.umeta.profile_id)
);
this.setState({ isProgress: false })
RNRestart.Restart();
} else if (response.data.type == "error") {
this.setState({ isProgress: false });
alert("Please Check Your Email / Password or Check Network ");
}
})
.catch(error => {
console.log(error);
});
}
Keyboard.dismiss();
};
在IOS情况下,它在响应后以
.then
进行移动,而在ANDROID中则以.catch
进行移动
最佳答案
请从此更改链接:
response.data.profile.umeta.id
对此:JSON.stringify(response.data.profile.umeta.id)
我认为那应该为您完成工作。
关于javascript - Axios请求在iOS上显示响应,但不适用于android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60389447/