Initial commit
This commit is contained in:
32
utils/storage.js
Normal file
32
utils/storage.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import JSONBigint from 'json-bigint';
|
||||
export default {
|
||||
get(key) {
|
||||
if (!key) console.error('key不能为空');
|
||||
|
||||
let result = uni.getStorageSync(key);
|
||||
try {
|
||||
result = JSONBigint.parse(result);
|
||||
|
||||
} catch (e) {}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
set(key, value) {
|
||||
if (!key) console.error('key不能为空');
|
||||
typeof value === 'object' && (value = JSONBigint.stringify(value));
|
||||
try {
|
||||
uni.setStorageSync(key, value)
|
||||
} catch (e) {
|
||||
console.log("数据存储错误", e)
|
||||
}
|
||||
},
|
||||
|
||||
remove(key) {
|
||||
uni.removeStorageSync(key);
|
||||
},
|
||||
|
||||
clean() {
|
||||
uni.clearStorage();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user