From c4cc07868023e086eecf40198974cf1651274cfd Mon Sep 17 00:00:00 2001 From: Chopper Date: Fri, 18 Jun 2021 17:06:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=B1=BB=E4=BF=A1=E6=81=AF=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E6=9B=B4=E6=96=B0=E6=97=B6=E9=97=B4=E8=AE=BE=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- buyer/src/components/nav/cateNav.vue | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/buyer/src/components/nav/cateNav.vue b/buyer/src/components/nav/cateNav.vue index e4fd092c..07a6b4eb 100644 --- a/buyer/src/components/nav/cateNav.vue +++ b/buyer/src/components/nav/cateNav.vue @@ -93,6 +93,11 @@ export default { getCategory(0).then(res => { if (res.success) { this.cateList = res.result; + // 过期时间 + var expirationTime = new Date().setHours(new Date().getHours() + 1); + // 存放过期时间 + localStorage.setItem('category_expiration_time', expirationTime); + // 存放分类信息 localStorage.setItem('category', JSON.stringify(res.result)) } }); @@ -117,7 +122,12 @@ export default { } }, mounted () { - if (localStorage.getItem('category')) { + if (localStorage.getItem('category') && localStorage.getItem('category_expiration_time')) { + // 如果缓存过期,则获取最新的信息 + if (new Date() > localStorage.getItem('category_expiration_time')) { + this.getCate(); + return; + } this.cateList = JSON.parse(localStorage.getItem('category')) } else { this.getCate()