vue-cli proxytable 跨域代理配置

1.配置位置:config文件夹下index.js

2.proxy文件

如果接口中不含/api_100这个接口时的配置文件,(把target为http://192.168.1.10/web_test/index.php/api2_100的地址映射为/api_100,pathRewrite将/api_100替换为空,)
附一个醍醐灌顶的链接 https://segmentfault.com/q/1010000012607105/a-1020000012607329
module.exports = {
proxy: {
'/api_100': {
target: 'http://192.168.1.10/web_test/index.php/api2_100',
secure: false,
changeOrigin: true, // 是否跨域
pathRewrite: {
'^/api_100': '' // 需要rewrite的地址
}
}
}
}

如果接口中包含/api_100这个接口时的配置文件
module.exports = {
proxy: {
'/api_100': {
target: 'http://192.168.1.10/web_test/index.php',
secure: false,
changeOrigin: true, // 是否跨域
}
}
}

 3.上述配置代表,在发请求http://192.168.1.10/web_test/index.php/api2_100/login的时候就可以写成/api_100/login,就能代理成功。

原文地址:https://www.cnblogs.com/fairy62/p/10930361.html