JavaScript获取url参数

233 阅读1分钟
const getParams = () => {
    let params = {};
    let str = window.location.hash || window.location.search;
    str.slice(1).split('&').forEach((item) => params[item.split('=')[0]] = item.split('=')[1]);
    return params
};