使用fetch时,报错
前端使用fetch()时,报错如下:
SyntaxError: Unexpected end of input
at eval (eval at <anonymous> (http://localhost:8280/dist/dist.js?v=@VERSION@:2695:2), <anonymous>:670:29)
并且打印response显示status是0
错误原因 及 解决方法
我在响应头(header)里加了跨域请求的配置:mode: ‘no-cors’,去掉就好了。 参考:https://stackoverflow.com/questions/32837916/response-status-0-using-fetch-polyfill-with-mode-no-cors
stackoverflow上给出的解释是: no-cors mode is only to CDN content, such as scripts, CSS and image, you cannot be used for getting data,response.status = 0 is right behavior