当前位置:网站首页>After the applet wx.setstoragesync, sometimes it can't get data with getstoragesync
After the applet wx.setstoragesync, sometimes it can't get data with getstoragesync
2022-07-23 07:13:00 【Weirdo haha】
background :
I can't get the store number on the shopping cart page 
problem :
yes wx.getStorageSync It is caused by not getting a value .
Current implementation :
Yes, save it after obtaining it wx.setStorageSync("merchantNo", userStoreInfo.data.merchantNo),
Take it directly every time you use it merchantNo: wx.getStorageSync("merchantNo").
solve :
1、 Write it directly as asynchronous acquisition , When the value cannot be obtained, go to the background again ;2、 When it is put into the cache, it is also saved into the global variable , The value is taken from the global or cache , If you can't get the data at this time, you can ask for re assignment asynchronously .
async goAgain(e) {
let params_ = {
orderNo: e.currentTarget.dataset.orderNo,
// merchantNo: wx.getStorageSync("merchantNo")
merchantNo: await this.getMerchantNo()
}
console.log('params_', params_)
oneMoreOrder(params_).then(res => {
if (res.code == 0) {
NCart.initNum()
wx.switchTab({
url: "/pages/shopping/cart"
});
} else {
wx.showToast({
title: res.msg,
duration: 2000,
icon: "none"
})
}
})
},
async getMerchantNo () {
try {
let value = wx.getStorageSync('merchantNo')
if (value) {
return value
}
let userStoreInfo = await getUserMerchant()
return userStoreInfo.data.merchantNo
} catch (e) {
console.log('eeee', e)
}
},
Reference article :
Applet wx.setStorageSync after , In use getStorageSync Sometimes it is impossible to obtain data
Use wx.getStorageSync Can't get value why ?
Wechat applet - Set local cache and read ( Sync , asynchronous )
边栏推荐
- FileInputFormat.setInputPaths多路径读取规则
- [matlab project practice] analysis of spatial and temporal characteristics of drought in a region based on SPI index
- 小黑leetcode之旅:590. N 叉树的后序遍历
- XSS必备知识
- Database system design: partition
- 关注公众号免费领取小米移动电源是真的吗?微信朋友圈送小米移动电源
- 织梦dedecms忘记管理后台密码找回方法
- Q6ui布局操作
- 小马激活工具出现Cannot open file k:\OEMSF 的解决方法
- Why is the computer screen yellowing? What is the reason for the yellowing of the monitor screen and the troubleshooting method
猜你喜欢

Combing the docking process between the integration base and the business system

Pikachu靶场-SQL注入-搜索型注入过关步骤

Zhimeng dedecms forgot to manage the background password retrieval method

Kali-工具-sqlmap常见用法

【高并发基石】多线程、守护线程、线程安全、线程同步、互斥锁

Common operators

Flink data source disassembly and analysis (Wikipedia editssource)

动作活体检测能力,构建安全可靠的支付级“刷脸”体验

Realize OPC UA publish/subscribe single send

小程序wx.setStorageSync后,在用getStorageSync获取数据有时会获取不到
随机推荐
小米活期宝和余额宝哪个好?小米活期宝与阿里余额宝区别详细对比介绍
【MATLAB项目实战】基于SPI指数的某地区地区干旱时空特征分析
Why is the computer screen yellowing? What is the reason for the yellowing of the monitor screen and the troubleshooting method
ESP32:Arduino教程汇总
Is it safe to apply for a stock trading account online?
数据库系统设计:分区
电脑提示内存不足怎么办 电脑C盘不够用的解决办法
怎么让自己在how old robot显得年轻?我看起来几岁更年轻方法技巧
OWA动态密码短信认证方案,解决outlook邮件双因子认证问题
如何把网站添加为可信任 可信任站点设置教程
电脑分区时出现'磁盘上没有足够的空间完成此操作'的解决办法
Demo19-(待更新)
CloudWeGo 在飞书管理后台平台化设计实践
What key should I press to release the computer from sleep mode when the computer is standby
How to do if the control panel program cannot be uninstalled? Compulsory uninstallation software tutorial
Scientific computing and Simulation - a brief introduction and application of the nonlinear least square problem of Gauss Newton method
Q6ui布局操作
thinkphp URL_ Mode =0 specific usage of normal mode
vim文本编辑器
中年危机,不敢离职的职场爸爸,该如何面对生活的苟且