有两种方式:

  1. 修改package.json文件的dev,后面加上--host 0.0.0.0,或者自己的局域网ip地址,例:--host 192.168.0.33
"scripts": {
    "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js --host 0.0.0.0",
    "build": "node build/build.js",
    "start": "npm run build:client && npm run build:server && cross-env NODE_ENV=production node server",
    "build:client": "cross-env NODE_ENV=production webpack --config build/webpack.client.conf.js --progress --hide-modules",
    "temp": "node tools/app.js",
    "build:server": "cross-env NODE_ENV=production webpack --config build/webpack.server.conf.js --progress --hide-modules",
    "lint": "eslint --ext .js,.vue src",
    "karma": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run"
  },

2.Vue配置文件config下面的index.js把locahost改成0.0.0.0

dev: {
    port: 8000,
    autoOpenBrowser: true,
    host: '0.0.0.0',
}