本地启动前端项目,如何让外部通过ip去访问 | 您所在的位置:网站首页 › 外网可以访问内网地址吗 › 本地启动前端项目,如何让外部通过ip去访问 |
前言:在实习中,遇到了本地启动vue-cli/create-react-app项目,想要用ip去访问本地启动的项目。 一:部署ip和localhost都可以访问本地vue-cli项目在配置文件vue.config.js中,找到devServer对象的host属性。(vue-cli将host主机名定义为localhost,从而导致了本地IP不能访问服务) host: 'localhost', // can be overwritten by process.env.HOST方法一:配置文件中的host属性重新定义为:0.0.0.0 host: '0.0.0.0'方法二:查看package.json文件,将scripts下的dev属性增加 --host 0.0.0.0 "scripts": { "serve": "rimraf -rf ./node_modules/.cache/vue-loader && vue-cli-service serve --host 0.0.0.0", "build": "vue-cli-service build", "test": "vue-cli-service build --mode test", "lint": "vue-cli-service lint" }, |
CopyRight 2018-2019 实验室设备网 版权所有 |