vue+flask前后端分离
跨域问题
解决办法:
vue 中:
main.js中 添加
axios.defaults.baseURL = 'http://localhost:11260'
创建vue.config.js
module.exports = {
devServer: {
proxy: {
'/': {
target: 'http://139.224.234.178:11260/',
changeOrigin: true,
pathRewrite: {
'^/': '/'
}
}
}
},
publicPath: process.env.NODE.ENV === 'production'
? '/shop_flask/'
: '/'
}
flask
manager.py中加入
# 跨域设置
@app.after_request
def cors(resp):
resp.headers.add('Access-Control-Allow-Origin','*')
resp.headers.add('Access-Control-Allow-Headers','*')
resp.headers.add('Access-Control-Allow-Methods','GET,PUT,POST,DELETE')
return resp