From 6cc41f38a853bb52da147b61723ec359745527fa Mon Sep 17 00:00:00 2001 From: GzhiYi Date: Tue, 5 Oct 2021 18:07:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BA=86=E5=88=86?= =?UTF-8?q?=E7=B1=BB=E7=9A=84=E5=8A=A0=E8=BD=BD=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- miniprogram/app.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/miniprogram/app.js b/miniprogram/app.js index a27e382..c5b16a4 100644 --- a/miniprogram/app.js +++ b/miniprogram/app.js @@ -45,7 +45,15 @@ App({ }, // 在app.js处进行分类的获取,以便所有页面方便使用 getCategory() { - // const self = this + // 在获取分类数据之前,优先读取本地缓存的数据 + const storeCategory = wx.getStorageSync('category') + const storeDefaultCategory = wx.getStorageSync('defaultCategory') + if (storeCategory) { + store.data.categoryList = storeCategory + } + if (storeDefaultCategory) { + store.data.defaultCategoryList = storeDefaultCategory + } return new Promise((resolve, reject) => { const categoryList = {} const defaultCategoryList = [] @@ -69,6 +77,15 @@ App({ } }) }) + // 将分类缓存在本地,优先读取,后续更新 + wx.setStorage({ + key: 'category', + data: categoryList + }) + wx.setStorage({ + key: 'defaultCategory', + data: defaultCategoryList + }) store.data.defaultCategoryList = defaultCategoryList resolve(res) }