第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

訪問 XMLHttpRequest:https://identitytoolkit.

訪問 XMLHttpRequest:https://identitytoolkit.

慕碼人2483693 2023-10-14 18:54:59
從源“http://localhost:8080”訪問“https://identitytoolkit.googleapis.com/v1/accounts:/signUp?key=AIzaSyDvZN5PKdB_b9jX-5rA-t9e3KSxJ-qtkdU”處的 XMLHttpRequest 已被 CORS 策略阻止:對預(yù)檢請求的響應(yīng)未通過訪問控制檢查:無“Access-Control-Allow-Origin”我嘗試在 vue.js 中使用 Axios 在 firebase 中創(chuàng)建新用戶,但出現(xiàn)上述錯誤。這是我的代碼示例。onSubmit () {    const formData = {      email: this.email,      age: this.age,      password: this.password,      confirmPassword: this.confirmPassword,      country: this.country,      hobbies: this.hobbyInputs.map(hobby => hobby.value),      terms: this.terms    }    console.log(formData)    axios.post('signUp?key=AIzaSyDvZN5PKdB_b9jX-5rA-t9e3KSxJ-qtkdU', {      email: formData.email,      password: formData.password,      returnSecureToken: true,    })    .then((res) => {        console.log(res)    })    .catch((error) => {      console.log(error)    })  }這是我的默認 axios 實例代碼。import axios from 'axios'const instance = axios.create({    baseURL: 'https://identitytoolkit.googleapis.com/v1/accounts:'});instance.defaults.headers.common['Access-Control-Allow-Headers'] = 'X-Requested-With, content-type';instance.defaults.headers.common['Access-Control-Allow-Origin'] = 'X-Requested-With, content-type';export default instance;
查看完整描述

1 回答

?
達令說

TA貢獻1821條經(jīng)驗 獲得超6個贊

CORS 是一個非常煩人的錯誤,實際上它是一場噩夢。

解決此問題的一種方法是使用代理,例如https://cors-anywhere.herokuapp.com。

獲取示例:

 var proxyUrl = 'https://cors-anywhere.herokuapp.com/',

    targetUrl = 'https://request-url.com'

fetch(proxyUrl + targetUrl)

  .then(blob => blob.json())

  .then(data => {

     var stringed = JSON.stringify(data);

     const res = JSON.parse(stringed);


     // Use res to access JSON

  })

  .catch(e => {

    console.log(e);

    return e;

  });

當然,這個例子只是為了獲取,但我相信你可以修改它以與 axios 一起使用。


如果您使用 NodeJS,請?zhí)砑有衏onst fetch = require("node-fetch");.


查看完整回答
反對 回復(fù) 2023-10-14
  • 1 回答
  • 0 關(guān)注
  • 251 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號