将来自 Axios 调用的响应推送到 Firebase - Vue.js

Pushing Response From Axios Call To Firebase - Vue.js

我正在对 api 进行 axios 调用,并得到了所需的响应。但是,我现在需要接受该响应并将其推送到我的 firebase Firestore 中。我知道如何推送到 firestore,但我似乎无法从 axios 推送调用正确访问数据。这是我的代码:

axios.get('https://somewhereontheweb.com/api/getgames', {
          headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            'Authorization': 'Bearer ' + token,
          }
        })
          .then(response => {
            this.games = response.data;

            // push data into firestore?
          })
          .catch(function (error) {
            console.log(error);
          });

我从 api 得到一个 json 数组并且可以在我的 vue 页面上显示它(此时它是一个对象)(所以 {{games}})。但是,我需要获取该数据,对其进行迭代,并在每次迭代中将游戏数据推送到 firestore 中。你能解释一下怎么做吗?我可以编写代码来推送到 firestore,但我无法编写代码来迭代 axios 调用的响应以推送到 firebase。我一直在努力,但没有取得任何进展。任何提示都很棒。

谢谢!

因为它是一个 JSON 字符串,所以您可以使用类似这样的方法对其进行迭代,以将其操作为您想要的数据结构:

for(var i in response.data){
  response.data[i].dosomething()
}

此外,将迭代传递给辅助函数可能是个好主意,并承诺最终将其发送到 Firestore。