Vue脚手架项目配置proxyTable代理,大佬绕道勿喷

264 阅读1分钟

创建的就先不说了:vue init webpack 项目名称

新手调试项目必备的技能,修改项目启动的端口号,配置接口代码,允许局域网的xdm访问我的项目地址。

VUE脚手架项目:gitee.com/shuogesha/b…

找到构建配置的目录config/index.js,直接上代码

核心代码dev下面

// Paths

proxyTable: {

'/api/': { //api为代理接口地址

// target:"http://192.168.1.118:9002/mall/",//这里是我的代理地址

target: "http://localhost:8080/", //这里是我的代理地址

changeOrigin: true, // 是否允许跨越

pathRewrite: {

'^/api': '/api'

}

},

'/upload/': { //api为代理接口地址

// target:"http://192.168.1.118:9002/mall/",//这里是我的代理地址

target: "http://localhost:8080/", //这里是我的代理地址

changeOrigin: true, // 是否允许跨越

pathRewrite: {

'^/upload': '/upload'

}

}

},

修改端口

// Various Dev Server settings

host: '0.0.0.0', // can be overwritten by process.env.HOST

port: 18080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined