点击table tr项后,页面跳转到下级页面,返回回显搜索条件、当前页码、并将点击项select选中、滚动条也被记录回显跳转时滚动的位置html
思路:vue
1.页面临时缓存我选择使用sessionStorage,点击tr行将搜索条件和页码,点击行的id进行存储;ios
setSessionStore (name, content) { if (!name) return if (typeof content !== 'string') { content = JSON.stringify(content) } window.sessionStorage.setItem(name, content) }, getSessionStore (name) { if (!name) return; var content = window.sessionStorage.getItem(name); if (typeof content == 'string') { content = JSON.parse(content) } return content; }, removeSessionStore (name) { if (!name) return return window.sessionStorage.removeItem(name) } }
2.进入页面取出sessionStorage,在init请求返回值后,进行table选中、分页回显;element-ui
data(){ return { paginationShow: false, 控制分页器显示 页面中使用v-if pager:{ total: 0, currentPage: 1, pageSize: 20, } } }
形成的缘由:咱们返回当前页面取得总条数totalNum以前,element-ui的分页组件已经在页面加载完毕,当时的totalNum绑定的是data里面初始化的数据0,因此当总条数为0的时候,分页组件的页码默认为1。而且当totalNum在created生命周期里取得数据后,分页组件也不会刷新。因此这就致使, 页面内容正确,可是页码高亮依旧是第一页。axios
解决办法:咱们须要在created以后刷新这个分页组件或者让分页组件的html后于created以后加载到页面。再次刷新这个分页组件是不现实的,咱们选择在created以后加载分页组件。具体办法就是使用v-if。在totalNum不为data里面给的初始值0的时候,才让这段html加载到页面。缓存
init () { axios.post('/url',param).then(function (response) { // 进行数据复制loading等操做 if(!myVM.paginationShow){ if(myVM.storeId){ **myVM.$nextTick(function(){** var storage = []; myVM.dataTable.forEach(function(item, index){ if(item.clueId === myVM.storeId ){ storage.push(myVM.dataTable[index]); } }) myVM.toggleSelection(storage); // 根据存储的滚动位置,将table滚动位置回显在页面上 **myVM.$el.querySelector('.el-table__body-wrapper').scrollTop = mycustomVM.scrollTop; ** }) } }else{ myVM.removeSessionStore ("storeForm"); myVM.removeSessionStore ("otherVal"); } mycustomVM.paginationShow = true; mycustomVM.storeForm = mycustomVM.form; }) }, toggleSelection(rows) { // table select 默认选中 if (rows) { rows.forEach(row => { this.$refs.multipleTable.toggleRowSelection(row,true); }); } else { this.$refs.multipleTable.clearSelection(); } }, toLink(row){ // 跳转进行存储 var clueId=row.clueId; this.setSessionStore("storeForm", this.storeForm); var otherVal = { "currentPage": this.pager.currentPage, "clueId": clueId, "scrollTop": **this.$el.querySelector('.el-table__body-wrapper').scrollTop** } this.setSessionStore("otherVal", otherVal); window.location.href='跳转连接,可携带参数'; }, mounted(){ document.getElementById('myVue').style.display = 'block'; }, created(){ // 进入页面判断有是否有存储值,取出后,进行初始化init函数 if(!this.paginationShow){ var storeVal = this.getSessionStore("storeForm"); var otherVal = this.getSessionStore("otherVal"); if(storeVal && otherVal){ this.form = storeVal; this.$set(this.pager,"currentPage",otherVal.currentPage); this.storeId = otherVal.clueId; this.scrollTop = otherVal.scrollTop; } } } window.sessionStorage.clear(); // 点击侧边栏、退出时-清除全部cookie(若是帐号被挤掉,退出的时候须要多考虑一下)
实现思路是这样,具体代码要根据实际项目开发cookie