数据本地存储

This commit is contained in:
jqtmviyu@gmail.com 2021-02-25 16:40:00 +08:00
parent 3a2ad8e278
commit 0d83e8259b

View File

@ -45,23 +45,31 @@ export default {
scrollTop: 0 scrollTop: 0
} }
}, },
onLoad(){ async onLoad(){
this.getCategories() //
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: { 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);
},
// //
onMenuTap(menuCurrent) { onMenuTap(menuCurrent) {
this.menuCurrent = menuCurrent this.menuCurrent = menuCurrent
@ -69,9 +77,7 @@ export default {
// 0, // 0,
this.scrollTop = Math.random() / 1000; this.scrollTop = Math.random() / 1000;
} }
} }
} }
</script> </script>
@ -146,9 +152,6 @@ export default {
image { image {
width: 70%; width: 70%;
} }
.goods_name{
}
} }
} }
} }