数据本地存储

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
methods: { const cate = uni.getStorageSync("categories")
// if(cate){
async getCategories(){ // 10,
const { message } = await this.$u.api.getCategories() if(Data.now() - cate.time > 1000 * 10){
// message = (await this.$u.api.getCategories()).message
categoryData = message uni.setStorageSync("categories", { time: Date.now(), list: message });
console.log(categoryData); }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.menus = message.map(v=>(v.cat_name))
// console.log(this.menu)
// //
this.goods = message[this.menuCurrent].children this.goods = message[this.menuCurrent].children
// console.log(this.goods); //
categoryData = message
}, },
methods: {
// //
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{
}
} }
} }
} }