如果用户在VueJS中输入错误的值,如何防止用户进入特定页面?
例如,我有从我的代码中撷取的代码片段,用于验证用户选择的日期是否与JSON中的日期匹配。
checkBirthday: function() {
//compare results birthday and input birthday
let inputBDAY = moment(this.date).format("MMMM DD, YYYY");
if (this.results.BIRT_D == inputBDAY) {
//redirect to details page
this.$router.push("/details/" + this.MEMB_N);
} else {
alert("Wrong Birthday");
}
}
这是我的routes.js片段
{
path: '/details/:MEMB_N', component: details
},
如果验证为true,我只希望重定向页面,如果为false,则希望阻止页面。
现在:即使我不验证生日也可以访问所需的页面
在“安全”页面/组件上使用导航保护。阅读this