My original address: https://dongkelun.com/2019/03/28/vueAutoIpAndOpenBrowser/
Foreword
Features such as the title, this reference: https://www.jianshu.com/p/54daac2cc924 , just to check the information on the Internet to be a note ~
The following items are created vue cli2
Automatically open the browser
Just need to find the config / index.js in autoOpenBrowser set it to true
Get local ip
method one
Add in config / top 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';
}
To find host changed it to host: localhost to
Effect Code View: https://github.com/dongkelun/vue-echarts-map/blob/autopip-v1/config/index.js
Method Two
Installation address
npm i address -D
在config/index.js
const address = require('address')
const localhost = address.ip() || 'localhost'
To find host changed it to host: localhost to
Effect Code View: https://github.com/dongkelun/vue-echarts-map/blob/master/config/index.js
Reproduced in: https: //www.jianshu.com/p/8397760571aa