axios关于跨域问题

axios 跨域

先放报错信息:
经过研究N次,是跨域设置问题,

XMLHttpRequest cannot load http://192.168.0.109:8080/farmer/user/register#/. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:8081’ is therefore not allowed access.

说一下怎么解决的
首先我在自己的代码中post(url,[config])放了
headers:{“Content-Type”: “application/x-www-form-urlencoded;charset=utf-8”,}
当然这不是影响的重点 也不影响.但是先记录
重点:后端小伙伴设置Httpresponse.setHeader(Access-Control-Allow-Origin: *)就完事了,= = 把锅甩给后台了,

前端有必要的话也可以在config index.js中 找到dev块 然后来一个 跨域:true 允许跨域 ,
放一个正常请求响应的所有信息
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42360556/article/details/83069034