我似乎无法理解为什么当我的网络应用程序在本地运行良好时 Firebase 返回错误 400

问题描述

我使用 Vue 2 在 javascript 中创建了一个项目。我的项目包括通过 URL 从 Binance API 获取数据。

为了获取数据,我使用了 fetch API。对于数据,我基本上将其存储在变量中,然后应用一些基本算法。

在本地,一切正常,但我的目标是将我的项目发布为 Web 应用程序。为此,我想使用 Firebase。

我已按照文档部署我的项目。在我的仪表板上,我可以清楚地看到我的项目已完全部署。当我单击提供的链接时,问题就出现了。我的 Web 应用程序向我抛出错误:400 Bad Request。我想知道 Firebase 和我通过 URL 获取数据之间是否存在干扰?

我想知道是否有人可以帮助我我似乎无法弄清楚是什么导致了这个错误

抱歉通过代码片段上传我的代码。我无法使用代码示例格式化程序显示我的代码 这是我第一次在 Stackoverflow 上上传...

这是我的主要组件:

<template>
  <div class="container">
    <div class="subContainer">
      <button @click="toggleBest">+</button>
      <h1 style="text-align:center">Best Futures</h1>
      <div v-if="showBest">
        <div class="displayCoins">
          <label>Nom</label>
          <label>Prix 1</label>
          <label>Prix </label>
        </div>
        <div class="bestFuture">
          <div>{{ max_object_first_future.name }}</div>
          <div>{{ max_object_first_future.first_contract }}%</div>
          <div>-</div>
        </div>
        <div class="bestFuture">
          <div>{{ max_object_second_future.name }}</div>
          <div>-</div>
          <div>{{ max_object_second_future.second_contract }}%</div>
        </div>
      </div>
    </div>

    <div class="subContainer">
      <button @click="toggleLog">+</button>
      <h1 style="text-align:center">Futures Log</h1>
      <div v-if="showLog">
        <div class="displayCoins">
          <label>Nom</label>
          <label>Prix 1</label>
          <label>Prix 2</label>
        </div>
        <crypto-coin
          v-for="(future,idx) in futures_array"
          :key="idx"
          :cryptoName="future.name"
          :firstContract="future.first_contract"
          :secondContract="future.second_contract"
        >
        </crypto-coin>
      </div>
    </div>
  </div>
</template>

<script>
import CryptoCoin from "./CryptoCoin.vue";
export default {
  components: {
    CryptoCoin,},created() {
    this.dataGetter();
  },data() {
    return {
      url: "https://dapi.binance.com//dapi/v1/ticker/bookTicker",max_object_first_future: {},max_object_second_future: {},showLog: false,showBest: false,futures_array: [
        {
          name: "BTC",data: [],first_contract: 0,second_contract: 0,{
          name: "ETH",{
          name: "LINK",{
          name: "BNB",{
          name: "TRX",{
          name: "DOT",{
          name: "ADA",{
          name: "EOS",{
          name: "LTC",{
          name: "BCH",{
          name: "XRP",{
          name: "ETC",{
          name: "FIL",{
          name: "EGLD",{
          name: "DOGE",{
          name: "UNI",{
          name: "THETA",{
          name: "XLM",],};
  },methods: {
    toggleLog() {
      this.showLog = !this.showLog;
    },toggleBest() {
      this.showBest = !this.showBest;
    },async dataGetter() {
      setInterval(async () => {
        this.resetData(this.futures_array);
        const response = await fetch(this.url);
        const data = await response.json();
        for (let prop in data) {
          if (data[prop]["pair"] === "BTCUSD") {
            this.futures_array[0].data.push(data[prop]);
          }
          if (data[prop]["pair"] === "ETHUSD") {
            this.futures_array[1].data.push(data[prop]);
          }
          if (data[prop]["pair"] === "LINKUSD") {
            this.futures_array[2].data.push(data[prop]);
          }
          if (data[prop]["pair"] === "BNBUSD") {
            this.futures_array[3].data.push(data[prop]);
          }
          if (data[prop]["pair"] === "TRXUSD") {
            this.futures_array[4].data.push(data[prop]);
          }
          if (data[prop]["pair"] === "DOTUSD") {
            this.futures_array[5].data.push(data[prop]);
          }
          if (data[prop]["pair"] === "ADAUSD") {
            this.futures_array[6].data.push(data[prop]);
          }
          if (data[prop]["pair"] === "EOSUSD") {
            this.futures_array[7].data.push(data[prop]);
          }
          if (data[prop]["pair"] === "LTCUSD") {
            this.futures_array[8].data.push(data[prop]);
          }
          if (data[prop]["pair"] === "BCHUSD") {
            this.futures_array[9].data.push(data[prop]);
          }
          if (data[prop]["pair"] === "XRPUSD") {
            this.futures_array[10].data.push(data[prop]);
          }
          if (data[prop]["pair"] === "ETCUSD") {
            this.futures_array[11].data.push(data[prop]);
          }
          if (data[prop]["pair"] === "FILUSD") {
            this.futures_array[12].data.push(data[prop]);
          }
          if (data[prop]["pair"] === "EGLDUSD") {
            this.futures_array[13].data.push(data[prop]);
          }
          if (data[prop]["pair"] === "DOGEUSD") {
            this.futures_array[14].data.push(data[prop]);
          }
          if (data[prop]["pair"] === "UNIUSD") {
            this.futures_array[15].data.push(data[prop]);
          }
          if (data[prop]["pair"] === "THETAUSD") {
            this.futures_array[16].data.push(data[prop]);
          }
          if (data[prop]["pair"] === "XLMUSD") {
            this.futures_array[17].data.push(data[prop]);
          }
        }
        for (const coins in this.futures_array) {
          this.calculateFutures(this.futures_array[coins]);
        }
        this.findMaxValue(this.futures_array);
      },2000);
    },resetData(array) {
      for (const coin in array) {
        array[coin].data = [];
        array[coin].first_contract = 0;
        array[coin].second_contract = 0;
      }
    },calculateFutures(object) {
      object.first_contract = 0;
      object.second_contract = 0;
      if (object.data.length === 1) {
        object.first_contract = 0;
        object.second_contract = 0;
      }
      if (object.data.length === 2) {
        object.first_contract = parseFloat(
          ((object.data[1].bidPrice / object.data[0].bidPrice - 1) * 100).toPrecision(7)
        );
      }
      if (object.data.length === 3) {
        object.first_contract = parseFloat(
          ((object.data[1].bidPrice / object.data[0].bidPrice - 1) * 100).toPrecision(7)
        );
        object.second_contract = parseFloat(
          ((object.data[2].bidPrice / object.data[0].bidPrice - 1) * 100).toPrecision(7)
        );
      }
    },findMaxValue(array) {
      let max_first_future = Math.max(...array.map((value) => value.first_contract));
      let max_second_future = Math.max(...array.map((value) => value.second_contract));
      max_first_future.toFixed(4);
      max_second_future.toFixed(4);
      this.max_object_first_future = array.find((value) => value.first_contract === max_first_future);
      this.max_object_second_future = array.find((value) => value.second_contract === max_second_future);
    },};
</script>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)