【问题标题】:How can i bypass cors error on the client side when building web apps?构建 Web 应用程序时如何绕过客户端的 cors 错误?
【发布时间】:2021-05-19 07:03:48
【问题描述】:

我正在尝试使用 axios 在我的 nuxt 应用程序中向 githubjobs API 发出获取请求。我已经正确设置和配置了 axios。这是我要调度的操作:

  async defaultJobsFetch({commit}){
    try{
      const res = await axios.get('https://jobs.github.com/positions.json?location=new+york')
      const jobs = res.data;
      commit('getJobs', jobs)
    }catch(error){
      commit("errored");
      console.log(error)
    }
    finally{
      commit('changeLoading')
    }
  },

我也尝试使用https://cors-anywhere.herokupp.com/,但仍然收到错误 403 禁止

我注意到它在我的本地机器上运行良好,但是当我部署并尝试加载已部署的应用程序时,我没有得到响应,而是收到 403 错误。该应用托管在heroku,http://hubjobs.herokuapp.com,访问该站点时检查控制台以查看错误

【问题讨论】:

    标签: javascript api axios nuxt.js


    【解决方案1】:

    一种解决方法是使用 chrome 扩展,如 CORS unblock 或尝试在标题中添加:

    访问控制允许来源:*

    【讨论】:

      【解决方案2】:

      【讨论】:

        猜你喜欢
        • 2019-04-30
        • 2012-11-23
        • 2017-07-19
        • 2019-04-27
        • 1970-01-01
        • 2021-08-16
        • 1970-01-01
        • 2010-10-06
        • 1970-01-01
        相关资源
        最近更新 更多