vue beforeRouteLeave beforeRout

2019-05-22  本文已影响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)
  }
}
上一篇 下一篇

猜你喜欢

热点阅读