如何正确使用axios.all?

时间:2019-11-20 15:24:49

标签: axios

我尝试使用axios.all,但是它不起作用。知道怎么做吗? axios.all永远不会被打电话。

axios.get('https://graph.facebook.com/v5.0/me/accounts?fields=id,name&access_token=' + response.accessToken)
.then(response => {
  console.log("test")
  let allAx = [];
  var pages = {};
  let pageList = response.data.data.map(page => {
    console.log("page " + page.id + " " + page.name);

    let ax = axios.get('https://graph.facebook.com/v5.0/' + page.id + '/events?access_token=' + accessToken)
    .then(response => {
      console.log("test 2");
      var events = {};
      let eventList = response.data.data.map(event => {
        console.log("event " + event.id + " " + event.name);
        events[event.id] = event.name;
      });
      pages[page.id] = [page.name, events];
    })
    allAx.push(ax)
  })

  axios.all(allAx)
  .then(axios.spread(function (acct, perms) {
    this.setState({
      pages: pages
    });
  }));

})

0 个答案:

没有答案