[英]How to instantly redirect the user to a new page via router when the user logs in succesfully(password, username are correct)
Via vue.js I've made a login form with a username and password, and set conditions for them. 通过vue.js我创建了一个包含用户名和密码的登录表单,并为它们设置了条件。 When the user submits the correct username and password I want to redirect them to a new page vie the vue.js Router. 当用户提交正确的用户名和密码时,我想通过vue.js路由器将它们重定向到新页面。 So for example if the user is currently located in "localhost8080/", after a successful login I want to immediately send them to "localhost8080/#/profile" 因此,例如,如果用户当前位于“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.
}
}
If You using vue-router, better to use programmatic navigation. 如果你使用vue-router,最好使用程序化导航。
Link: https://router.vuejs.org/guide/essentials/navigation.html 链接: https : //router.vuejs.org/guide/essentials/navigation.html
if(loginConfirmed) {
this.$router.push({ path: 'dashboard' });
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.