-
zhangwei
2024-08-14 ff120d19df422dc6aeb7a35e144d726582aef8f8
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
 
//取值
function get(key, sync = true) {
    try {
        if (sync) {
            return uni.getStorageSync(key);
        } else {
            let data = '';
            uni.getStorage({
                key: key,
                success: function (res) {
                    data = res.data;
                }
            });
            return data;
        }
    } catch (e) {
        return false;
    }
}
 
//赋值
function set(key, value, sync = true) {
    try {
        if (sync) {
            return uni.setStorageSync(key, value);
        } else {
            uni.setStorage({
                key: key,
                data: value
            });
        }
    } catch (e) {
 
    }
}
 
//移除
function del(key, sync = true) {
    try {
        if (sync) {
            return uni.removeStorageSync(key);
        } else {
            uni.removeStorage({
                key: key
            });
        }
    } catch (e) {
        return false;
    }
}
 
//清空
function clear(sync = true) {
    try {
        if (sync) {
            return uni.clearStorageSync();
        } else {
            uni.clearStorage();
        }
    } catch (e) {
        return false;
    }
}
 
export {
    get,
    set,
    del,
    clear
}