reactjs - vue中的相同功能反应错误
问题描述
我在 Vue(工作)中有一个 JWT 身份验证,我试图更改为 React(它的后端相同)。在 console.log(this.state.email) 中,我收到了正确的电子邮件,与密码相同。我认为问题出在 'try{const response = await axios.post("api/auth/login"...' 我不能仅在 Vue 中通过 React
反应错误:
EnvioLogin = async () => {
console.log(this.state.email)
console.log(this.state.password)
try {
const response = await axios.post("api/auth/login", { email: this.state.email, password: this.state.password });
localStorage.setItem("token", response.data.token);
if (response.status === "200") {
this.getUsers();
console.log(response);
this.props.history.push("/app");
}
} catch (error) {
this.setState({ error: "User or Password wrong!" });
setTimeout(() => {
this.setState({ error: "" });
}, 2000);
}
};
Vue 正确:
async EnvioLogin() {
try {
console.log(this.email);
console.log(this.password);
const response = await axios.post("api/auth/login", {
email: this.email,
password: this.password,
});
localStorage.setItem("token", response.data.token);
if (response.status == "200") {
this.getUsers();
console.log(response);
this.$router.push("intermediorotas");
this.showLogin = false;
}
} catch (error) {
this.showError = true;
setTimeout(() => {
this.showError = false;
}, 2000);
}
},
解决方案
推荐阅读
- if-statement - 用于条件格式自定义函数的 Countblank 和 ImportRange
- html - 如何使文本在 CSS 中的框中居中?我的没用
- node.js - Google App Engine - 部署 nodejs 应用程序时缺少目录
- excel - 希望返回给定公司名称的行的最大值
- html - '已添加具有相同密钥的项目'
- three.js - 将 MeshStandardMaterial 复制到 ShaderMaterial 时如何渲染 PMREM 环境贴图
- entity-framework - 在 select LINQ 子句和方法中创建新对象有什么区别
- join - 关系代数-fullouterjoin
- sql-server - 使用变量表将多条记录插入/合并到一条记录中以打印在明信片的两面
- android - 具有约束布局的 NestedScrollView 作为子项不滚动