找了好久好像大多数免费的能前端获取用户IP的API都用不了.
let xhr = new XMLHttpRequest();xhr.open('GET', 'https://ip.useragentinfo.com/json');xhr.responseType = 'json';xhr.send();xhr.onreadystatechange = function() {if (xhr.readyState === 4) {let ipinfo = xhr.response;console.log(ipinfo);console.log(ipinfo.ip);}}