Skip to content

Commit

Permalink
feat: 优化了分类的加载速度
Browse files Browse the repository at this point in the history
  • Loading branch information
GzhiYi committed Oct 5, 2021
1 parent e6cdaf6 commit 6cc41f3
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion miniprogram/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -69,6 +77,15 @@ App({
}
})
})
// 将分类缓存在本地,优先读取,后续更新
wx.setStorage({
key: 'category',
data: categoryList
})
wx.setStorage({
key: 'defaultCategory',
data: defaultCategoryList
})
store.data.defaultCategoryList = defaultCategoryList
resolve(res)
}
Expand Down

0 comments on commit 6cc41f3

Please sign in to comment.