middleground_H5/utils/localStorage.js

26 lines
672 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const localStorage = {
// 存储数据到本地缓存
set(key, value) {
uni.setStorageSync(key, value)
},
// 从本地缓存中读取数据
get(key) {
return uni.getStorageSync(key)
},
// 更新本地缓存中的数据
update(key, value) {
// 获取原有的数据
let oldValue = this.get(key)
if (oldValue !== null && typeof oldValue === 'object') {
// 如果原有数据为对象则使用Object.assign()方法进行合并
value = Object.assign({}, oldValue, value)
}
this.set(key, value)
},
// 从本地缓存中删除数据
remove(key) {
uni.removeStorageSync(key)
}
}
export default localStorage