提交 | 用户 | age
|
aeb317
|
1 |
export function getQueryObj() { |
J |
2 |
let search = location.search.replace('?', '') |
|
3 |
const obj = {} |
|
4 |
if (!search) { |
|
5 |
return obj |
|
6 |
} |
|
7 |
if (search.indexOf('&') > -1) { |
|
8 |
search = search.split('&') |
|
9 |
} else { |
|
10 |
search = [search] |
|
11 |
} |
|
12 |
|
|
13 |
search.forEach(item => { |
|
14 |
const [key, value] = item.split('=') |
|
15 |
if (!obj[key]) { |
|
16 |
obj[key] = value |
|
17 |
} else { |
|
18 |
if (obj[key] instanceof Array) { |
|
19 |
obj[key].push(value) |
|
20 |
} else { |
|
21 |
obj[key] = [obj[key], value] |
|
22 |
} |
|
23 |
} |
|
24 |
}) |
|
25 |
|
|
26 |
return obj |
|
27 |
} |