VUE:-Error- vue开发模式正常,部署后提示fetch跨域

本文探讨了在Vue项目中遇到的跨域问题,特别是在部署后使用fetch请求数据时出现的错误。通过调整baseUrl的设置,从'//xxxx.com'更改为'//www.xxxxx.com',解决了因主域名与子域名不一致导致的跨域访问限制。
vue开发fetch正常,部署后报错如下

Failed to load http://guozhaoip.com/good/front/classList: Response to
preflight request doesn’t pass access control check: No
‘Access-Control-Allow-Origin’ header is present on the requested
resource. Origin ‘http://www.guozhaoip.com’ is therefore not allowed
access. If an opaque response serves your needs, set the request’s
mode to ‘no-cors’ to fetch the resource with CORS disabled.

解决办法

  • 将env.js中
  • baseUrl = '//xxxx.com';
  • 改为
  • baseUrl = '//www.xxxx.com';
  • 原因为xxxx.com 与 www.xxxx.com不再同一个域。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值