前端从url获取数据
const getParameters = (URL) => {
URL = jsON.parse(
'{"' +
decodeURI(URL.split("?")[1])
.replace(/"/g, '\\"')
.replace(/&/g, '","')
.replace(/=/g, '":"') +
'"}'
);
return jsON.stringify(URL);
};
getParameters(window.location);
或者:
Object.fromEntries(new URLSearchParams(window.location.search))