stroage.js
740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function setItem(key, value, module_name) {
if (module_name) {
let module_name_info = getItem(module_name) || {};
module_name_info[key] = value;
try {
wx.setStorageSync(module_name, module_name_info);
} catch (e) {
wx.setStorage({
key: module_name,
data: module_name_info
})
}
} else {
try {
wx.setStorageSync(key, value);
} catch (e) {
wx.setStorage({
key: key,
data: value
})
}
}
}
function getItem(key, module_name) {
if (module_name) {
let val = getItem(module_name);
if (val) return val[key];
return '';
}
return wx.getStorageSync(key)
}
function clear(name) {
name ? wx.removeStorageSync(name) : wx.clearStorageSync()
}
module.exports = {
setItem,
getItem,
clear
}