簡體   English   中英

當用戶成功登錄時,如何通過路由器立即將用戶重定向到新頁面(密碼,用戶名是正確的)

[英]How to instantly redirect the user to a new page via router when the user logs in succesfully(password, username are correct)

通過vue.js我創建了一個包含用戶名和密碼的登錄表單,並為它們設置了條件。 當用戶提交正確的用戶名和密碼時,我想通過vue.js路由器將它們重定向到新頁面。 因此,例如,如果用戶當前位於“localhost8080 /”,成功登錄后我想立即將它們發送到“localhost8080 /#/ profile”

                validate() {
                var email = document.getElementById("email").value;
                var atSign = email.indexOf("@");

                var error = document.getElementById("error");
                var mistakes = "";
                var hasErrors = false;

                if (this.newP != this.password){
                    mistakes += "Entered password is incorrect. ";
                    hasErrors = true;
                }

                if (atSign === -1) {
                    mistakes += "The email is missing an '@' sign.";
                    hasErrors = true;
                }
                // console.log(this.newP.length)
                if (hasErrors === true) {
                    error.innerHTML = mistakes;
                    return false;
                } else {
                    alert("Login confirmed");
                    return true;
                //I realize it's supposed to be here, but I do not know                                                                
                //how to write it.
                }
                }

如果你使用vue-router,最好使用程序化導航。

鏈接: https//router.vuejs.org/guide/essentials/navigation.html

if(loginConfirmed) {
    this.$router.push({ path: 'dashboard' });
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM