1.問題描述
點擊登錄按鈕,調取接口,成功后獲取數據并跳轉到首頁,都沒有問題,也沒有報錯,就是點擊第一次不跳轉,第二次才能跳轉,這是代碼
this.$message({message: "登陸成功",type: "success",});this.$router.push("/home/picture");sessionStorage.setItem("token", res.data.token);
2.解決方法
試了好幾次才發現這個問題出現的原因是,在點擊登錄按鈕,數據獲取成功時先進行跳轉然后再把數據存儲在本地;(先跳轉,再存儲)
解決方法:先把數據存儲在本地,再進行頁面跳轉。(先存儲,再跳轉)
this.$message({message: "登陸成功",type: "success",});sessionStorage.setItem("token", res.data.token);
this.$router.push("/home/picture");