封装获取url参数的公共函数

// 获取url参数
        urlQuery() {
            const href = location.href;
            if (href.indexOf('?') > -1) {
                const aa = href.substring(href.lastIndexOf('?'));
                const a = aa.split('?');
                const b = a[1];
                // 多个参数
                if (b.indexOf('&') > -1) {
                    const c = b.split('&');
                    const obj = {};
                    c.map(function(item) {
                        const d = item.split('=');
                        obj[d[0]] = d[1];
                    });
                    return obj;
                } else {
                    // 一个参数
                    const obj = {};
                    const c = b.split('=');
                    obj[c[0]] = c[1];
                    return obj;
                }
            }
        }

你可能感兴趣的:(js)