当前位置: 代码迷 >> 综合 >> Access to XMLHttpRequest at ‘http://139.224.234.178:11260/user/login‘ from origin ‘http://localhost:
  详细解决方案

Access to XMLHttpRequest at ‘http://139.224.234.178:11260/user/login‘ from origin ‘http://localhost:

热度:89   发布时间:2023-11-27 21:41:45.0

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

  相关解决方案