uni-app uni.setStorageSync这个API在HarmonyOS系统不兼容
uni-app uni.setStorageSync这个API在HarmonyOS系统不兼容
开发环境 | 版本号 | 项目创建方式 |
---|---|---|
Windows | 无 | HBuilderX |
操作步骤:
uni.setStorageSync(tokenKey, data);
let date = new Date(new Date().getTime() + expires_in * 1000);
let dateString = this.getFullTime(date);
console.log(dateString)
uni.setStorageSync(expiresInKey, dateString);
预期结果:
可以走完整个逻辑
实际结果:
console.log(dateString)都没办法打印
bug描述:
手机:华为Pura 70
HarmonyOS版本:5.0.0
平台:微信小程序
具体描述:微信小程序登陆的时候,用到了uni.setStorageSync这个api来存储用户信息,发现鸿蒙系统的微信小程序不执行这代码,导致代码逻辑没办法往下走,直接登陆不了。
更多关于uni-app uni.setStorageSync这个API在HarmonyOS系统不兼容的实战教程也可以访问 https://www.itying.com/category-93-b0.html
看文档:https://uniapp.dcloud.net.cn/api/storage/storage.html#setstorage
uni.setStorageSync没有明确说支持HarmonyNext OS.
你可以用 uni.setStorage, 这个是支持HarmonyNext OS的。
更多关于uni-app uni.setStorageSync这个API在HarmonyOS系统不兼容的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
为啥其他都做了兼容,唯独这个不做一下兼容呢?
回复 6***@qq.com: 不知道啊,得官方来解答了。。。
在HarmonyOS系统的微信小程序中遇到uni.setStorageSync不兼容的问题,可以尝试以下解决方案:
-
检查基础库版本:确保微信小程序基础库版本足够新,旧版本可能存在API兼容性问题。
-
使用异步API替代:尝试改用uni.setStorage异步API,看是否能正常工作:
uni.setStorage({
key: tokenKey,
data: data,
success: () => {
let date = new Date(new Date().getTime() + expires_in * 1000);
let dateString = this.getFullTime(date);
console.log(dateString);
uni.setStorage({
key: expiresInKey,
data: dateString
});
}
});
-
检查存储权限:确认小程序是否有足够的存储权限,可以尝试在manifest.json中配置所需权限。
-
异常捕获:添加try-catch块捕获可能的异常:
try {
uni.setStorageSync(tokenKey, data);
let date = new Date(new Date().getTime() + expires_in * 1000);
let dateString = this.getFullTime(date);
console.log(dateString);
uni.setStorageSync(expiresInKey, dateString);
} catch (e) {
console.error('存储失败:', e);
}