nuxtjs axios跨源资源共享问题

时间:2019-12-19 15:43:54

标签: vue.js vuejs2 firebase-authentication axios nuxt.js

我目前正在使用nuxtjs并尝试集成Firebase auth rest api。但是我在chrome控制台中遇到错误:

从原点“ https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=IHaveRemovedTheTokenWhilePostingThisToStackOverflow”到“ http://localhost:3000”的XMLHttpRequest的访问已被CORS策略阻止:对预检请求的响应未通过访问控制检查:否

中出现了Access-Control-Allow-Origin标头。

我该如何解决这个问题?

这是我的设置

在pages / login.vue目录

submitLogin(){
          this.$axios.post('https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=' + process.env.firebaseApiToken,
            {
            email: "abc@example.com",
            password: "123456"
            }, {
              headers: {
                'Access-Control-Allow-Origin': '*',
                'Content-Type': 'application/Json'
              }
            }).then((response) => {
              console.log(response.data);
          })
        }

在nuxtjs.config.js中

axios: {
    credentials: false
  },

在package.json中

"dependencies": {
    "nuxt": "^2.0.0",
    "@nuxtjs/axios": "^5.3.6"
  },

1 个答案:

答案 0 :(得分:0)

只需在nuxt.config.js中添加代理配置

您可以在https://nuxtjs.org/faq/http-proxy/

中找到示例