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);
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM