需求 列表進入詳情后,返回詳情的時候保留搜索的條件,第幾頁進入的返回還在第幾頁
1.在詳情頁設置定義一個字段
mounted() {sessionStorage.setItem("msgInfo", true);},
2.在獲取列表數據的時候在mounted里面判斷定義的字段
if (sessionStorage.getItem("msgInfo")) {//如果有就讀取緩存里面的數據this.pageNum = Number(sessionStorage.getItem("currentPage"));//搜索的數據let data = JSON.parse(sessionStorage.getItem("search"));this.search = data;} else {this.pageNum = 1;//其他頁面第一次進入列表頁,清掉緩存里面的數據sessionStorage.removeItem("search");sessionStorage.removeItem("currentPage");}
進入詳情的時候保存一下頁碼和搜索的信息
details(data) {sessionStorage.setItem("currentPage", this.pageNum);sessionStorage.setItem("search", JSON.stringify(this.search));this.$store.commit("set_studentDetails", data);this.$router.push("/student_details");},
離開頁面的時候清除定義的字段
destroyed() {// 銷毀組件sessionStorage.removeItem("msgInfo");},