CatsAndMice / blog

📖 凌览的博客
http://www.linglan01.cn
79 stars 6 forks source link

实现一个函数用来解析 URL 的 querystring #27

Closed CatsAndMice closed 2 years ago

CatsAndMice commented 3 years ago
export function getUrlParams(url: string): Object {
    let params: any = {};
    let createUrl: URL = new URL(url);
    let search: string = createUrl.search;
    let strs: string[] = search.replace('?', '').split('&')
    for (const str of strs) {
        let [key, value] = str.split('=');
        params[key] = value;
    }
    return params;
}