//设置缓存
getlistdata(){
var that = this;
wx.request({
url: ‘https://api-hmugo-web.itheima.net/api/public/v1/categories’,
success(res) {
that.List = res.data.message[0].children[0].children
that.setData({
listdata: that.List
})
wx.setStorageSync(“listdata”, { data: that.List })
}
//加载缓存
onLoad: function (options) {
const Listdata = wx.getStorageSync(“listdata”);
if (!Listdata){
this.getlistdata();
} else {
this.setData({
listdata: Listdata.data
})
}
两次编译都会发起请求,但是第二次的数据量比较少,刚学小程序,麻烦大神们指点指点