1.首先找到config文件夾目錄下的 index.js文件
// Various Dev Server settings
//host: 'localhost'
//將localhost進(jìn)行替換成 0.0.0.0
host: '0.0.0.0', // can be overwritten by process.env.HOST
port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be de
2.然后找到package.json配置文件
//在這句代碼后面添加 --host 0.0.0.0" 如下
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js --host 0.0.0.0"",
3.配置一下build文件夾下面的webpack.dev.conf.js文件
devServer: {
useLocalIp: true, //將useLoackIp設(shè)置為true 就可以了
}
4.最后配置一下啟動(dòng)項(xiàng)目 通過localhost 和本地ip地址訪問
同樣還是在build文件夾下面的webpack.dev.conf.js文件找到文章來源:http://www.zghlxwxcb.cn/news/detail-519493.html
devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
compilationSuccessInfo: {
messages: [ //下面兩個(gè)地方,直接復(fù)制即可
`App runing at: `,
` - Local: http://localhost:${port}`, //配置這里
` - Network: http://${require('ip').address()}:${port}`,//配置這里
],
},
onErrors: config.dev.notifyOnErrors
? utils.createNotifierCallback()
: undefined
}))
5.最后看下一效果文章來源地址http://www.zghlxwxcb.cn/news/detail-519493.html
到了這里,關(guān)于VUE搭建項(xiàng)目,配置本地IP地址其他人可訪問項(xiàng)目的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!