-
配置Flask
# 安装flask_cors pip install flask_cors from flask_cors import * #全局配置 CORS(app, supports_credentials=True)
-
配置Vue
1.找到config目录下的index.js,在proxyTable下添加配置信息:
'/api': { target: 'http://localhost:5000/', //后端接口地址 changeOrigin: true, //是否允许跨越 pathRewrite: { '^/api': 'http://localhost:5000/' //路径重写 } }
![](https://img.haomeiwen.com/i9403344/10e8372429b51b34.png)
2.在axios中,请求地址改为:'api/xxx/xxx'
![](https://img.haomeiwen.com/i9403344/aaa1a996feda6586.png)
至此,跨域问题解决。
网友评论