原因:
例1: ‘http://a.a.com/data?id=1&time=2021-11-23’
此时通过 window.location.search 能够正常获取到url中的查询参数 ?id=1&time=2021-11-23
例2:‘http://a.a.com/#/data?id=1&time=2021-11-23’
此时通过 window.location.search 获取到的参数为空"",这是因为使用了hash导致,因为hash会将url中第一个#后的内容都作为hash内容,所以search为空了.
解决办法1:把#去掉
解决方法2:用 window.location.hash.split("?")[1];
var search = window.location.hash.split("?")[1];
console.log(search) //id=1&time=2021-11-23