JS获取url后的参数

JS获取url后的参数_第1张图片 
方法:
// 获取url后的参数
const getQuery = (path:any)=>{
    let [urlPath, urlStr] = (path && path.split('?')) || [];
    let extraData:any = {};
    let paramsArr = (urlStr && urlStr.split('&')) || [];
    for (let i = 0, len = paramsArr.length; i < len; i++) {
        let [key, value] = paramsArr[i].split('=');
        extraData[key] = value;
    };
    return extraData;
};

你可能感兴趣的:(前端,linux,javascript)