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,就能代理成功。
