【vue_django】成功登錄后,保存用戶


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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM