将变量传递给函数的ReferenceError

时间:2018-04-03 14:03:36

标签: javascript react-native callback

道歉,如果这是一个重复的问题,我不知道如何充分说出我的问题来搜索它:

当我尝试运行这段代码时:

var tempList = [];
var followingArr = [];
response.data.forEach(async (following, i) => {
    var numFollowers = 0;
    axios.get(following.followers_url)
        .then(async (response) => {
            numFollowers = response.length;
            followingArr.push({key: following.name, numFollowers: numFollowers});
            tempList.push({key: following.name, numFollowers: numFollowers, pic: this.state.followingPics[i]});
         })
         .catch((error) => {
             console.log(error);
         });
});

我一直收到错误Error fetching following: ReferenceError: Can't find variable: following。我猜这是因为我需要将变量传递给我axios.get以某种方式调用,但我并不完全确定如何。

0 个答案:

没有答案