其他分享
首页 > 其他分享> > vue 项目启动时将电脑的ip设置为启动时的端口号

vue 项目启动时将电脑的ip设置为启动时的端口号

作者:互联网

const os = require('os'); function getNetworkIp() {   let needHost = ''; // 打开的host   try {     // 获得网络接口列表     let network = os.networkInterfaces();     loop: for (let dev in network) {       let iface = network[dev];       for (let i = 0; i < iface.length; i++) {         let alias = iface[i];         if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {           needHost = alias.address;           break loop;         }       }     }   } catch (e) {     needHost = 'localhost';   }   console.log('这里是本机的ip:', needHost)   return needHost; }

标签:vue,network,启动,alias,iface,let,needHost,os,端口号
来源: https://www.cnblogs.com/sq652366/p/15716279.html