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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM