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 = '//guozhaoip.com';
- 改为
baseUrl = '//www.guozhaoip.com';
- 原因为guozhaoip.com 与 www.guozhaoip.com不再同一个域。