vue axios跨域访问解决

使用vue的axios组件来访问后台数据,如果后台没有进行设置,会遇到跨域问题。

提示:

No 'Access-Control-Allow-Origin' header is present on the requested resource.

后台如果是.net站点,那么我们只需要在服务器站点的web.config文件中,加入下面的节点就可以解决。

<system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Methods" value="OPTIONS,POST,GET" />
        <add name="Access-Control-Allow-Headers" value="x-requested-with,content-type" />
        <add name="Access-Control-Allow-Origin" value="*" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>

猜你喜欢

转载自blog.csdn.net/badaaasss/article/details/86646960