mui确定要离开当前页面吗?", "温馨提示", ["取消", "确定"]

要实现的需求是:一个需要输入数据提交的页面,在没有点击提交按钮退出当前页面的时候,让他弹出一个提示框如下
在这里插入图片描述

这是一个用mui实现的逻辑

history.pushState(null, null, document.URL);
window.addEventListener('popstate', function (e) {
  mui.confirm("确定要离开当前页面吗?", "温馨提示", ["取消", "确定"], function (e) {
    if (e.index == 1) {
      window.history.go(-1); // 向后移动一个页面
    } else {
      history.pushState(null, null, document.URL);
    }
  });
});

猜你喜欢

转载自blog.csdn.net/fengtingYan/article/details/89286724