我的原创地址:https://dongkelun.com/2019/03/28/vueAutoIpAndOpenBrowser/
前言
功能如题,本文参考:https://www.jianshu.com/p/54daac2cc924,目的只是为了把网上查的资料做个笔记~
以下均为vue cli2 创建的项目
自动打开浏览器
只需要在config/index.js里找到autoOpenBrowser将其设为true即可
获取本地ip
方法一
在config/index.js 顶部添加
const os = require('os')
let localhost = ''
try {
const network = os.networkInterfaces()
localhost = network[Object.keys(network)[0]][1].address
} catch (e) {
localhost = 'localhost';
}
再找到host将其改为host:localhost即可
效果代码查看:https://github.com/dongkelun/vue-echarts-map/blob/autopip-v1/config/index.js
方法二
安装address
npm i address -D
在config/index.js
const address = require('address')
const localhost = address.ip() || 'localhost'
再找到host将其改为host:localhost即可
效果代码查看:https://github.com/dongkelun/vue-echarts-map/blob/master/config/index.js
网友评论