From 51efaf1495baa7b3c175a7d72bfa2b23439294cb Mon Sep 17 00:00:00 2001 From: yison Date: Mon, 18 Mar 2019 20:40:44 +0800 Subject: [PATCH] feat: add page size storage function to Component Page --- src/components/page/page.vue | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/components/page/page.vue b/src/components/page/page.vue index 27f15bfc..65cfa4b0 100644 --- a/src/components/page/page.vue +++ b/src/components/page/page.vue @@ -144,6 +144,14 @@ nextText: { type: String, default: '' + }, + name: { + type: String, + default: '' + }, + cachePageSize: { + type: Boolean, + default: false } }, data () { @@ -229,6 +237,13 @@ [`${prefixCls}-item-active`]: this.currentPage === this.allPages } ]; + }, + pageSizeKey() { + if (this.cachePageSize && this.name !== null) { + return `pageSize_${this.name}`; + } else { + return null; + } } }, methods: { @@ -273,6 +288,9 @@ this.currentPageSize = pageSize; this.$emit('on-page-size-change', pageSize); this.changePage(1); + if (this.cachePageSize && this.name !== null) { + window.localStorage.setItem(this.pageSizeKey, pageSize); + } }, onPage (page) { this.changePage(page); @@ -308,6 +326,14 @@ this.changePage(page); } } + }, + mounted () { + if (this.cachePageSize && this.name !== null) { + const pageSize = window.localStorage.getItem(this.pageSizeKey); + if (this.pageSizeOpts.includes(pageSize)) { + this.currentPageSize = pageSize; + } + } } };