vue-cli3设置项目ip

1、创建vue.config.js

(cli3相对于cli2,之前的build和config文件夹不见了,那么应该如何配置 如webpack等的配那只需要在项目的根目录下vue.config.js
文件(是根目录,不是src目录))

module.exports = {
    devServer: {
      port: 8080, // 端口号
      host: "localhost",
      https: false, // https:{type:Boolean}
      open: true, //配置自动启动浏览器
      // proxy: 'http://localhost:4000' // 配置跨域处理,只有一个代理
      proxy: {
        "/api": {
        target: "<url>",
          ws: true,
          changeOrigin: true
        },
        "/foo": {
          target: "<other_url>"
        }
      } // 配置多个代理
    }
  };

以上为基础配置

2、修改config.js配置

//host:"localhost"
host:"0.0.0.0"

讲proxy(跨域代理)中的target的路径改为自己的ip(IPv4地址)

target:"局域网ip"
//例如
          target: "http://10.0.100.174",

猜你喜欢

转载自blog.csdn.net/ANNENBERG/article/details/107491461