主要是處理用戶退出logout的邏輯
后端controller層
設定了一個@RequiresAuthentication的注解
@RequiresAuthentication
@GetMapping("/logout")
public Result logout(){
System.out.println("logout");
SecurityUtils.getSubject().logout();
return Result.success("已退出", null);
}
前端代碼
vue部分
<div class="text-align-right">
<span>當前用戶:{{ username }}</span>   
<span><el-link type="danger" @click="logout"> 退出</el-link></span>
</div>
vue的<script>部分
methods: {
logout() {
const _this = this
this.$axios.get("/logout", {
headers: {
"Authorization": localStorage.getItem("token")
}
}).then((res) => {
_this.$store.commit('REMOVE_INFO')
_this.$router.push('/')
});
}
}問題出現在下面這一行
"Authorization": localStorage.getItem("token")不知道為什么"Authorization"不能正確拿到值
已經嘗試過:
1. 將Authorization改成authorization,不行;
2. 去掉引號,直接
Authorization: localStorage.getItem("token")同樣出錯3. 改成任意變數名,如aaa
"aaa": localStorage.getItem("token")瀏覽器console不報錯,但是后臺的controller層的logout()是不會觸發的,因為Authorization沒有獲取到現在的問題是是什么原因導致Authorization不能獲取到呢?
PS:我的另一個專案是正常的,代碼一模一樣,但是現在這個不行
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/268724.html
標籤:JavaScript
上一篇:檢測資料
下一篇:阿里一直響156678
