微信小程序wx.getStorage获取不到数据,wx.getStorageSync能够获取到,这是什么原因呢?
//存储
static async setCurrentPatient(patientId: string) {
await wx.setStorage({ key: 'PATIENT_ID', data: patientId })
}
获取
export async function getStorage(key: string): Promise<any> {
try {
await wx.getStorage({ key ,
success:function (res) {
return res.data;
},});
// const res = await wx.getStorageSync(key); //用这个可以获取到缓存的数据
} catch (e) {
return null;
}
}
一个是异步的,一个是同步的。要不发下你的代码看看?
你试下先写个简单的:
如果还不行,试一下加complete,看看会返回什么?