在onload页面调用async函数后,需要该函数里的一个数据,但是onload加载完了才能等到?
发布于 6 年前 作者 wdai 4167 次浏览 来自 问答

在onload页面调用async函数后,需要该函数里的一个数据,但是onload加载完了才能等到数据打印出来,需要这一数据的程序语句在async函数的数据传过来之前已经被执行完了,不是想要的结果,totalexamNum(默认为0)是totalAsync()函数传过来的值(在改函数中可以打印输出),但是在下面的for语句中totalexamNum始终为0,请问该如何解决呢?

onLoad: function (options) {

let that = this

var receive = that.totalAsync().then(res => {

// res就是结果数组

console.log( res);

 

}).catch(rej => {

console.log(rej);

})

for(let i = ; i < 100; i++) {

Arr[i] = Math.floor(Math.random()*(totalexamNum))

}

 

}

1 回复

问题是,你 totalexamNum 没赋值啊,不为0应该为多少?

回到顶部