let url = window.location.href;//http://localhost:3000/edu/edu_teacher?type=2&a=3
if(url.indexOf('?') != -1){
    let obj = {};
    let arr = url.slice(url.indexOf('?')+1).split('&');
    arr.forEach(item => {
        let param = item.split('=');
        obj[param[0]] = param[1];
    })
    console.log(obj);//{type: "2", a: "3"}
    alert(obj.type);
    return obj;
}else{
    console.log('没有参数');
    alert('没有参数');
    return null;
}

 

posted on 2021-05-21 10:03  月零Ray  阅读(1430)  评论(0编辑  收藏  举报