在完成之前的承诺后,将调用以下函数。
map()遍历具有数据的数组,这三个数组是使用twit软件包从twitter获得数据的3个承诺。
接收到的数据没有任何错误,但是map()有时会导致错误,并且有时会在没有特殊原因的情况下完美地运行。
未定义的部分只发生在map()的返回部分内部,然后才进行控制台操作。记录与每次迭代相同的记录,但是在到达“ url:x”行时出现错误。
是异步问题吗?
如果不是,那么console.log(x)也应该在同一迭代中给出错误。
尝试了forEach和for循环遇到相同的问题。
flatenarr : function (error) {
if(!error){
const newarray = this.dataurl.flat();
let x ;
let copy = newarray.map((e,index)=>{
x = e.extended_entities.media[0].media_url;
console.log(x); // x is always logged and defined
if(true){ // just to remove other errors using static true
return{
id: e.id + Math.floor(Math.random() * (index) + (index + 10)),
text: e.full_text,
// following line gives error and the code breaks
url: x,
}
}
});
// imgurl is what is passed to the children components
this.imgUrl = copy;
this.isShowing = true;
}
}