!5 【轻量级PR】:修复从本地缓存中同步获取和移除指定key时因未重新获取本地缓存导致的BUG

Merge pull request !5 from 耿嘉祺/master
This commit is contained in:
若依 2023-07-10 06:14:54 +00:00 committed by Gitee
commit 47a18b8422
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -6,9 +6,6 @@ let storageKey = 'storage_data'
// 存储节点变量名 // 存储节点变量名
let storageNodeKeys = [constant.avatar, constant.name, constant.roles, constant.permissions] let storageNodeKeys = [constant.avatar, constant.name, constant.roles, constant.permissions]
// 存储的数据
let storageData = uni.getStorageSync(storageKey) || {}
const storage = { const storage = {
set: function(key, value) { set: function(key, value) {
if (storageNodeKeys.indexOf(key) != -1) { if (storageNodeKeys.indexOf(key) != -1) {
@ -19,9 +16,11 @@ const storage = {
} }
}, },
get: function(key) { get: function(key) {
let storageData = uni.getStorageSync(storageKey) || {}
return storageData[key] || "" return storageData[key] || ""
}, },
remove: function(key) { remove: function(key) {
let storageData = uni.getStorageSync(storageKey) || {}
delete storageData[key] delete storageData[key]
uni.setStorageSync(storageKey, storageData) uni.setStorageSync(storageKey, storageData)
}, },