vue element 点击按钮返回上一页

如何通过点击的方式控制当前页返回到上一个路由页面:

<el-button plain @click="returnPage">取消</el-button>
// 返回上一级
    returnPage(){
    
    
      if (window.history.length <= 1) {
    
    
        this.$router.push({
    
     path: "/system/storageManagement" });
        return false;
      } else {
    
    
        this.$router.go(-1);
      }
    },

这个判断用来解决这种情况,当用户没有上一条路由的历史记录,出现点击返回按钮没有反应时,下面的代码用来判断有没有上一条路由的历史记录

this.$router.go(val) => 在history记录中前进或者后退val步,当val为0时刷新当前页面、-1即为返回上一页;

猜你喜欢

转载自blog.csdn.net/weixin_45895806/article/details/111293002