1.vueaxios跨域请求,后台已配置允许跨域,代理访问的时候还报错跨域2.配置了代理访问地址还是localhostaxios.defaults.headers.common['Access-Control-Allow-Origin']="*";axios.defaults.headers.post['Content-Type']='application/x-www-form-urlencoded';proxyTable:{'/apis':{target:'http://192.168.1.109/xxx/aa',changeOrigin:true,pathRewrite:{'^/apis':''}}}this.$http.post('/apis/bbb/cccc',{json:JSON.stringify({})}).then(function(response){console.log(response);}).catch(function(error){console.log(error);});3.请求结果报错RequestheaderfieldAccess-Control-Allow-OriginisnotallowedbyAccess-Control-Allow-Headersinpreflightresponse.Error:Requestfailedwithstatuscode404atcreateError(createError.js?16d0:16)atsettle(settle.js?db52:18)atXMLHttpRequest.handleLoad(xhr.js?ec6c:77)
2 回答
开满天机
TA贡献1786条经验 获得超13个赞
你这个报错是因为你的请求中除了安全的头部字段额外加了Access-Control-Allow-Origin,后台并不允许这个字段解决办法后台配置响应头Access-Control-Allow-Headers中加上Access-Control-Allow-Origin
添加回答
举报
0/150
提交
取消