解决 vue CLI2.5以下版本本地项目启动后不能被外部IP访问

1,  修改 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 

这里把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,


2,修改 build/webpack.dev.conf.js 的 devServer 配置

增加 disableHostCheck = true

devServer: {

clientLogLevel:'warning',

  historyApiFallback: {

rewrites: [

{from:/.*/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') },

    ],

  },

  hot:true,

  contentBase:false, // since we use CopyWebpackPlugin.

  compress:true,

  host: HOST ||config.dev.host,

  port: PORT ||config.dev.port,

  open:config.dev.autoOpenBrowser,

  overlay:config.dev.errorOverlay

    ? {warnings:false, errors:true }

:false,

  publicPath:config.dev.assetsPublicPath,

  proxy:config.dev.proxyTable,

  quiet:true, // necessary for FriendlyErrorsPlugin

  disableHostCheck:true,

这里是新增的 

  watchOptions: {

poll:config.dev.poll,

  }

3 查找到自己的IP地址

然后改成

http://192.168.199.168:8080/#/

这样就可以联动同步了

你可能感兴趣的:(解决 vue CLI2.5以下版本本地项目启动后不能被外部IP访问)