【发布时间】:2020-02-25 07:27:05
【问题描述】:
我正在使用axios 将一些数据发布到本机反应的服务器,但我遇到了一个问题,我的代码在 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
【问题讨论】:
-
错误在说什么?
-
@AndreiOlar 错误:java.lang.Double 无法在 convertError (AsyncStorage.js:345) at AsyncStorage.js:338 处转换为 java.lang.String 它显示此错误
标签: javascript android ios react-native axios