一、引入依赖包
const axios = require('axios')
二、请求接口
/** * 请求接口 */ async function getIP () { const { data } = await axios.request({ url: 'https://api.ipify.org/?format=json', method: 'get' }) const ip = _.get(data, 'ip', '') return ip }
三、获取IP
const ip = await getIP() console.log('----本机IP为----',ip)