分类信息缓存更新时间设定

master
Chopper 2021-06-18 17:06:25 +08:00
parent b3fda14322
commit c4cc078680
1 changed files with 11 additions and 1 deletions

View File

@ -93,6 +93,11 @@ export default {
getCategory(0).then(res => { getCategory(0).then(res => {
if (res.success) { if (res.success) {
this.cateList = res.result; 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)) localStorage.setItem('category', JSON.stringify(res.result))
} }
}); });
@ -117,7 +122,12 @@ export default {
} }
}, },
mounted () { 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')) this.cateList = JSON.parse(localStorage.getItem('category'))
} else { } else {
this.getCate() this.getCate()