美文网首页
10.uniapp简单封装

10.uniapp简单封装

作者: 秀萝卜 | 来源:发表于2020-04-14 09:35 被阅读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)
    }
    

    相关文章

      网友评论

          本文标题:10.uniapp简单封装

          本文链接:https://www.haomeiwen.com/subject/lozamhtx.html