解析查询字符串

2021-07-20  本文已影响0人  泡杯感冒灵
        getQueryStringArgs() {
            // 取得查询字符串并去掉开头的问号
            const qs = (location.search.length > 0 ? location.search.substring(1) : '');
            // 保存数据的对象
                const args = {};
                const items = qs.length ? qs.split('&') : [];
                let item = null;
                let name:any = null;
                let value = null;
                const len = items.length;
            for (let i = 0; i < len; i++) {
                item = items[i].split('=');
                name = decodeURIComponent(item[0]);
                value = decodeURIComponent(item[1]);
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        }
上一篇下一篇

猜你喜欢

热点阅读