getModalTip(){
wx.getStorage({
key: 'todayTimestamp',
success: function(res) {
console.log('222222222222222222',res)
if (res.data && res.data != new Date().toLocaleDateString()) {
wx.showModal({
content: '单位承担余额马上清零了,请您尽快消费!',
showCancel: false
})
}
},
fail: function(res) {
console.log(res);
wx.showModal({
content: '单位承担余额马上清零了,请您尽快消费!',
showCancel: false
})
wx.setStorage("todayTimestamp", new Date().toLocaleDateString());
console.log('5555555555',new Date().toLocaleDateString())
}
})
},
onLoad: function (options) {
this.getModalTip()
}
q前端想要实现弹框一天弹一次,但是为啥通过上述代码wx.getStorage每次都进入fail,每次都弹窗。
因为setStorage是key、data的形式。
wx.setStorage("todayTimestamp", new Date().toLocaleDateString()); 改为: wx.setStorage({ key: "todayTimestamp", data: new Date().toLocaleDateString() });
// 消费弹框提示
getModalTip() {
const todayTimestamp = wx.getStorageSync('todayTimestamp') || ''
const timeDialog = () => {
wx.showModal({
content: '单位承担余额马上清零了,请您尽快消费!',
showCancel: false
})
wx.setStorageSync("todayTimestamp", new Date().toLocaleDateString());
}
if (todayTimestamp) {
if (todayTimestamp !== new Date().toLocaleDateString()) { // 如果缓存里的时间不等于当前时间,弹窗,同时重新设置缓存时间为当前时间
timeDialog()
}
} else { // 缓存里没有日期,则弹窗并设置日期
timeDialog()
}
},
fail回调里 res返回啥?