const getParameters = (URL) => { URL = JSON.parse('{"' + decodeURI(URL.split("?")[1]).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') +'"}'); return JSON.stringify(URL); }; console.log(getParameters('http://localhost:8080/#/projectpage?id=7098&Vid=344&type=2'))
运行结果: