一:首先打开命令窗口
输入 : ipconfig 后,回车会看到本机的IP地址
二:打开vue项目文件在本机运行,在项目目录中的config 文件
紧接着我们会看到index.js 文件,在文件中找到如下代码行
dev: {
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {},
// Various Dev Server settings
host: 'localhost',
// can be overwritten by process.env.HOST 将此处localhost修改为'0.0.0.0'即可!
port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
autoOpenBrowser: false,
errorOverlay: true,
notifyOnErrors: true,
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
/**
* Source Maps
*/
// https://webpack.js.org/configuration/devtool/#development
devtool: 'cheap-module-eval-source-map',
// If you have problems debugging vue-files in devtools,
// set this to false - it *may* help
// https://vue-loader.vuejs.org/en/options.html#cachebusting
cacheBusting: true,
cssSourceMap: true
},
将该代码块中中host里面的localhost改为 '0.0.0.0', 然后一定记得重启项目:会发现终端中运行后的项目地址发生了改变,现在就可以在局域网中通过第一步中我们获取到的IP地址加端口号来访问该项目了