1.获取当前域名
window.location.origin // www.xxx.com
2.获取query参数
const getUrlCode = () => {
var url = window.location.href;
let urlStr = url.split('?')[1]
const urlSearchParams = new URLSearchParams(urlStr)
const result = Object.fromEntries(urlSearchParams.entries())
return result
}
console.log(getUrlCode(window.location.href), '结果')
// {
// id: "657"
// name: “猪”
// }