Cross-domain issues can also be addressed through this approach.
Use Http-proxy-middleware Agent solution (project using VUE-CLI scaffolding construction)
For example, the requested URL: "Http://f.apiplus.cn/bj11x5.json"
1. Open Config/index.js, add the following code in Proxytable:
| 123456789 |
proxytable: {    '/api ': { //use "/API" instead of "HTTP://F.APIPLUS.C"      target: '/HTTP/ F.apiplus.cn ',//source address      changeorigin:true,//Change source      pathrewrite: { ' ^/api ': ' http://f.apiplus.cn '//path rewrite        }     } |
2. Use "/API" directly when requesting data using Axios:
| 1234 |
getData () { axios.get(‘/api/bj11x5.json‘, function (res) { console.log(res) }) |
This approach solves the cross-domain, and when you package the deployment, there is a problem. Here's how to fix it:
| 12345 |
let serverUrl = ‘/api/‘ //本地调试时 // let serverUrl = ‘http://f.apiplus.cn/‘ //打包部署上线时 export default { dataUrl: serverUrl + ‘bj11x5.json‘ } |
When debugging, define a ServerURL to replace our "/API", finally packaging, only need to "http://www.xxx.com" replace the "/api" on it. Original website: https://www.cnblogs.com/wangyongcun/p/7665687.html
Vue+axios cross-Domain resolution method