第一步:修改config文件中找到 index.js 文件的host改成 ‘0.0.0.0’
dev: {
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {},
// Various Dev Server settings
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 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
}
第二步:检查 package.json 文件里进行配置,scripts.dev配置是否设置 host为‘0.0.0.0’
"scripts": {
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
"start": "npm run dev",
"build": "node build/build.js"
}
首先,这里每个项目的配置都不同,如果没有就不用设置
这里我要强调下,第一步和第二步都有ip,其实第二步优先级高,这里第二步的host可以不设置,vue默认执行第一步的设置。
这个ip也可以设置成你的局域网ip,例如:192.168.1.182
查看开发机的ip地址
MAC: ifconfig
Windows: ipconfig
最后别忘记把防火墙打开
MAC:
windows:
Comments | NOTHING