PS:使用session
保存: // 登錄 login() { if (this.username === "" || this.password === "") { alert("輸入框不能為空") } else { axios.post('/login/', { username: this.username, password: this.password }).then(response => { if (response.data['code'] == 200) { alert("登錄成功") sessionStorage.setItem('username', this.username) window.location.href = "index/" } else if (response.data['code'] == 444) { alert("賬號或者密碼錯誤") } }).catch(error => { console.log(error) alert("請求異常") }) } }
跳轉后輸出: <script> new Vue({ el: '#app', data: { }, // 實例創建后執行 created() { let myName=sessionStorage.getItem("username"); console.log("-----created-----", myName) }, }) console.log(myName) </script>