【node】为vue获取本机IP地址
获取本机ipv4地址:可通过,执行预览本地ip信息;
·
获取本机ipv4地址:
可通过cmd
,执行ipconfig/all
预览本地ip信息;
// vue.config.js
const os = require("os");
let needHost = "0.0.0.0";
try {
let network = os.networkInterfaces();
console.log(network);
needHost = network[Object.keys(network)[0]][1].address;
} catch {
needHost = "localhost";
}
console.log(needHost);
module.exports = defineConfig({
...
devServer: {
host: needHost,
port: 8080,
open: true,
proxy: {},
},
});
更多推荐
已为社区贡献8条内容
所有评论(0)