element-ui的分页中的页面查看详情后返回当前页码

1、列表页

methods() {
    //改变页数
    currentChange(val) {
      this.page.currentPage = val;
      //缓存当前页码数
      sessionStorage.setItem('currentPage',val);
      //调取表格列表接口
      this.getList();
    },
     //当从详情页返回的时候,先获取详情页中存下来的detall标识,在列表页中,把获取到的分页页码重新赋值,用以返回前的页面,保持不变
    getCurrentPage(){
      if(sessionStorage.getItem('detail')){
        //如果有这个就读取缓存里面的数据
       this.page.currentPage=Number(sessionStorage.getItem("currentPage"));
      }else{
        this.page.currentPage=1;
        //这个主要是从其他页面第一次进入列表页,清掉缓存里面的数据
        sessionStorage.removeItem("currentPage");
      }
    },
}

然后在mounted中执行这个方法

mounted() {
    this.getCurrentPage();
}

再在destroyed中销毁缓存

destroyed(){
    sessionStorage.removeItem("detail");
}

2、详情页

mounted() {
    //如果从详情页返回,从缓存中读取当前页码信息。此时缓存是否打开了详情页
    sessionStorage.setItem("detail",true);
}

 

posted @ 2021-08-02 13:05  小阿飞ZJF  阅读(1039)  评论(0编辑  收藏  举报