微信小程序如何处理页面缓存


微信小程序处理页面缓存的方法:

根据当前时间作为判断依据,缓存数据,代码:

Page({

data: {

},

onLoad: function () {

//this.getNowTime()

if(wx.getStorageSync("loaction_time")==this.getNowTime()){

//读取缓存

console.log("缓存地址");

var datevalue=wx.getStorageSync("loaction");

console.log(datevalue)

}else{

wx.removeStorageSync("loaction");

//请求地址

console.log("请求地址");

var loactionname="bs";

wx.setStorageSync("loaction",loactionname);

wx.setStorageSync("loaction_time",this.getNowTime());

var datevalue=wx.getStorageSync("loaction");

console.log(datevalue)

}

},getNowTime: function() {

var now = new Date();

var year = now.getFullYear();

var month = now.getMonth() + 1;

var day = now.getDate();

if(month < 10) {

month = '0' + month;

};

if(day < 10) {

day = '0' + day;

};

// 如果需要时分秒,就放开

var h = now.getHours();

var m = now.getMinutes();

var s = now.getSeconds();

//var formatDate = year + '-' + month + '-' + day + ' ' + h + ':' + m + ':' + s;

var formatDate = year + '-' + month + '-' + day;

//console.log('当前时间',formatDate)

return formatDate;

}

})


上一篇:用php建站选择什么服务器

下一篇:怎么查看电脑mysql服务是否打开


微信小程序 小程序 页面缓存
Copyright © 2002-2019 测速网 www.inhv.cn 皖ICP备2023010105号
测速城市 测速地区 测速街道 网速测试城市 网速测试地区 网速测试街道
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!

热门搜索 城市网站建设 地区网站制作 街道网页设计 大写数字 热点城市 热点地区 热点街道 热点时间 房贷计算器