There is a token in my localstorage. If I delete the token in localstorage then I don't log out. Can you give me an example of how to do this?
created() { if (this.vueToken) { let headers = { Authorization: "Bearer " + localStorage.getItem("vueToken"), }; axios .get("checkLogin", { headers: headers, }) .then((response) => response); }else{ this.$router.push('/login') } },
P粉5118967162024-03-31 10:49:32
You must set a condition in the security route, for example, if the token in local storage is empty, push it to local storage. Here is sample code.
mounted() { this.token = localStorage.getItem("ivToken"); if(this.token===null){ this.$router.push("/signin") }
},`