草庐IT

javascript - Vue 和 Axios CORS 错误 No 'Access-Control-Allow-Origin' header is present on the requested resource

coder 2024-05-12 原文

<分区>

我目前遇到上述错误,我正在使用 Axios 向外部 API 发出 GET 请求。看完Mozilla文档,做了很多研究并尝试了不同的选择,我仍然没有任何改善。

我已经将代码剥离回到基础:

axios.get('URL.com', {
        headers: {
          Access-Control-Allow-Origin: *
        },
        auth: {
          username: 'username',
          password: 'password'
        },
      })
      .then(function (response) {
        console.log(response);
      })
      .catch(function (error) {
        console.log(error);
      });

我是否需要向 header 添加任何其他内容?

一切都通过 Postman 工作,所以一旦我通过了 CORS 问题,一切都会工作。

有关javascript - Vue 和 Axios CORS 错误 No 'Access-Control-Allow-Origin' header is present on the requested resource的更多相关文章

随机推荐