很多時候遇到這種需求從列表第三頁點擊某個item進入到詳情頁,然后點擊瀏覽器后退按鈕退回到列表頁,這個時候往往回到了列表中第一頁的數據,如果我希望保持回到第三頁,該如何操作呢?
列表頁點擊分頁的方法中:
this.$router.push({path:"partList",query:{categoryname :this.categoryname,page:this.page}})
點擊分頁時除了重新調接口加載數據,還要跳到當前頁,但是要傳分頁的參數
在mounted() 方法中,加載數據時判斷分頁的參數是否有值,有的話是從詳情頁返回,沒有可能是其它頁面進入,判斷加載數據即可。
mounted() {
if(this.$route.query.page==undefined){
this.page=1;//意味着其它頁面進入,此時默認展示第一頁數據
}else{
this.page=this.$route.query.page;//記住之前的分頁
}
this.loadData(this.page);
},