仅允许用户通过验证后才能转到页面

问题描述 投票:0回答:1

如果用户在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,则希望阻止页面。

现在:即使我不验证生日也可以访问所需的页面

vue.js vuejs2 vue-router
1个回答
0
投票

在“安全”页面/组件上使用导航保护。阅读this

© www.soinside.com 2019 - 2024. All rights reserved.