当我使用正确的电子邮件/密码发送“EnvioLogin”时,我从“/login”获取访问令牌,但之后我无法获取“/users”,只有在我在浏览器中检查时,我才得到:https://i . stack.imgur.com/yBJK0.jpg https://i.stack.imgur.com/bWQEG.jpg
用户尝试登录后如何运行创建的挂钩?
import axios from "axios";
export default {
name: "login",
data() {
return {
showError: false,
email: "",
password: "",
};
},
async created() {
const response = await axios.get("api/users", {
headers: {
Authorization: "Bearer " + localStorage.getItem("token")
}
});
console.log(response);
},
methods: {
async EnvioLogin() {
try {
const response = await axios.post("api/auth/login", {
email: this.email,
password: this.password,
});
localStorage.setItem("token", response.data.token);
const status = JSON.parse(response.status);
if (status == "200") {
console.log(response);
this.$router.push("intermediorotas");
this.showLogin = false;
}
} catch (error) {
this.showError = true;
setTimeout(() => {
this.showError = false;
}, 2000);
}
},
},
慕哥9229398
相关分类