Bootstrap

【vue】vue.config.js里面获取本机ip:


一、效果:

image.png

二、实现:
const os = require('os');

function getLocalIpAddress() {
  const interfaces = os.networkInterfaces();
  for (let key in interfaces) {
    const iface = interfaces[key];
    for (let i = 0; i < iface.length; i++) {
      const alias = iface[i];
      if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
        return alias.address;
      }
    }
  }
  return '0.0.0.0';
}

console.log(getLocalIpAddress())

image.png

;