From 0d83e8259bf933c3159f8317b38dafe3ee0e0d22 Mon Sep 17 00:00:00 2001 From: "jqtmviyu@gmail.com" Date: Thu, 25 Feb 2021 16:40:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=9C=AC=E5=9C=B0=E5=AD=98?= =?UTF-8?q?=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/category/category.vue | 45 ++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/pages/category/category.vue b/src/pages/category/category.vue index 13352ba..b34c367 100644 --- a/src/pages/category/category.vue +++ b/src/pages/category/category.vue @@ -45,23 +45,31 @@ export default { scrollTop: 0 } }, - onLoad(){ - this.getCategories() + async onLoad(){ + // 数据本地存储 + let message = null + const cate = uni.getStorageSync("categories") + if(cate){ + // 数据超过10秒, 从新从接口拿数据并更新到本地 + if(Data.now() - cate.time > 1000 * 10){ + message = (await this.$u.api.getCategories()).message + uni.setStorageSync("categories", { time: Date.now(), list: message }); + }else { + // 没有过期 + message = cate.list + } + }else{ + message = (await this.$u.api.getCategories()).message + uni.setStorageSync("categories", { time: Date.now(), list: message }); + } + // 左列表获取 + this.menus = message.map(v=>(v.cat_name)) + // 右列表获取 + this.goods = message[this.menuCurrent].children + // 数据存到全局 + categoryData = message }, - methods: { - // 获取详情信息 - async getCategories(){ - const { message } = await this.$u.api.getCategories() - // 把接口所有的数据存到全局变量上 - categoryData = message - console.log(categoryData); - // 左列表获取 - this.menus = message.map(v=>(v.cat_name)) - // console.log(this.menu) - // 右列表获取 - this.goods = message[this.menuCurrent].children - // console.log(this.goods); - }, + methods: { // 点击左菜单 onMenuTap(menuCurrent) { this.menuCurrent = menuCurrent @@ -69,9 +77,7 @@ export default { // 一直为0没变化, 小程序不会发现 this.scrollTop = Math.random() / 1000; } - } - } @@ -146,9 +152,6 @@ export default { image { width: 70%; } - .goods_name{ - - } } } }