前提:手机和电脑处于同一网络(同一个路由器),电脑WiFi和手机WiF、电脑有线和手机wifi
一、打开cmd查询电脑IP
ipconfig
二、将电脑IP配置到vue的package.json中
dev: { host: '192.168.50.45', // 原为: hotst: 'localhost' }
--host 192.168.50.45
"scripts": { "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js --host 192.168.50.45", "start": "npm run dev", "build": "node build/build.js" },
根据自己的实际项目配置
修改config/index.js 中host:localhost为192.168.50.45
dev: { // Paths assetsSubDirectory: 'static', assetsPublicPath: '/', proxyTable: {}, // Various Dev Server settings host: '192.168.50.45', // 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 },
三、启动项目
npm run dev
四、手机打开链接
修改为自己的ip和端口号
http://192.168.50.45:8080