vue离开当前页面时给出提示,弹出框一闪而过

vue离开当前页面时给出提示,弹出框一闪而过

路由守卫就不说了,在离开当前页面给出提示时,发现弹出框一闪而过,不能阻塞进程(window.confirm原声的是可以的),但是这个不好看,我也懒得改(其实不会改);

这样解决加 延时执行!

if (to.fullPath == "/questionInfo/questionListTest" || to.fullPath == "/addUserInfo") {
          setTimeout(() => {  //此处必须要加延迟执行
            that.$confirm('将要离开此页面,是否离开', '温馨提示', {
            distinguishCancelAndClose: true,
            confirmButtonText: '离开',
            cancelButtonText: '继续答题',
            confirmButtonClass: "btn-class",
          })
          .then(() => {
            next();
          })
          .catch(action => {
            next(false);
          });
          }, 200);
        }

猜你喜欢

转载自blog.csdn.net/qq_38880700/article/details/88864383