我目前正在使用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"
},