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