10.uniapp简单封装

2020-04-14  本文已影响0人  秀萝卜
static setStorageSync2(data) {
        for (var i in data) {
            try {
                uni.setStorageSync(i, data[i]);
            } catch (e) {
            }
        }
    }

    static setStorageSync(name,data) {
        try {
            uni.setStorageSync(name, data);
        } catch (e) {
        }
    }

    static getStorageSync(name) {
        try {
            var value = uni.getStorageSync(name);
            return value;
        } catch (e) {
        }
    }


static go(name, data) {
        var url = "/pages/" + name + "/" + name
        if (data) {
            url = url + "?" + getParam(data);
        }
        console.log(url);
        var tabbar_arr = ["home", "type", "notes", "cart", "personal"]
        if (tabbar_arr.indexOf(name) > "-1") {
            uni.switchTab({ url: url })
        } else {
            uni.navigateTo({ url: url })
        }
    }

function getParam(data) {
    var param = "";
    for (var k in data) {
        let value = data[k] !== undefined ? data[k] : ''
        param += '&' + k + '=' + encodeURIComponent(value)
    }
    return param.substring(1)
}
上一篇下一篇

猜你喜欢

热点阅读