微信小程序处理页面缓存的方法: 根据当前时间作为判断依据,缓存数据,代码: Page({ data: { }, onLoad: function () {
根据当前时间作为判断依据,缓存数据,代码:
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;
}
})
--结束END--
本文标题: 微信小程序如何处理页面缓存
本文链接: https://www.lsjlt.com/news/116814.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-10
2024-05-10
2024-05-10
2024-05-10
2024-05-09
2024-05-09
2024-05-09
2024-05-09
2024-05-09
2024-05-09
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0