后端返回一个url字符串,可以直接使用a标签的href获取域名等信息:
const a = document.createElement('a'); a.href = 'https://www.baidu.com/s?a=1&b=1#hash'; console.log(a.host); // www.baidu.com console.log(a.pathname); // /s console.log(a.search); // ?a=1&b=1 console.log(a.hash); // #hash