美文网首页
vue beforeRouteLeave beforeRout

vue beforeRouteLeave beforeRout

作者: 芒果大饼 | 来源:发表于2019-05-22 11:38 被阅读0次

离开页面前的提示

  data() {
  },
  beforeRouteLeave(to, from, next) {
//mintui 弹窗组件
    this.$Messagebox
      .confirm("", {
        message: "Do you really want to leave? you have unsaved changes!",
        title: "提示",
        confirmButtonText: "确定",
        cancelButtonText: "稍后再说"
      })
      .then(action => {
        if (action == "confirm") {
          next();
        }
      })
      .catch(err => {
        if (err == "cancel") {
          next(false);
        }
      });
  },

进入页面前的提示

beforeRouteEnter(to, from , next) {
//window自带弹窗
  const answer = window.confirm('Do you really want to leave? you have unsaved changes!')
  if (answer) {
    next()
  } else {
    next(false)
  }
}

相关文章

网友评论

      本文标题:vue beforeRouteLeave beforeRout

      本文链接:https://www.haomeiwen.com/subject/usryzqtx.html