今天在练习Vue写简易个人博客时使用到了jsonplaceholder这个免费在线REST服务(其实就是提供测试用的HTTP请求假数据),然后在post的时候第一次出现了Access-Control-Allow-Origin这个error,这应该是第一次碰到跨域的问题吧,查了一个多小时才解决。
参考
具体情况
这个简易博客是用CLI2写的,为了测试数据用到了jsonplaceholder,在post时碰到了以下error:
1 | Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource |
解决方案
在index.html头文件中加入如下代码:
<meta http-equiv="Access-Control-Allow-Origin" content="*">
Author:oCodeHoney
Date:2020-6-8