通过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.
}
}发布于 2019-06-08 01:08:50
如果您使用vue-router,最好使用程序化导航。
链接:https://router.vuejs.org/guide/essentials/navigation.html
if(loginConfirmed) {
this.$router.push({ path: 'dashboard' });
}https://stackoverflow.com/questions/56498483
复制相似问题