今天遇到一个问题,在forEach中不会等待异步完成
ActivityImgPath[this.activityName].forEach((path,index) => async () => { const key = ActivityImgName[this.activityName][index]; await $asset.loadAsset(path, SpriteFrame).then(_asset => this.loadedAssets.set(key, _asset)); });
只能改成for循环了
for (let index = 0; index < ActivityImgPath[this.activityName].length; index++) { const path = ActivityImgPath[this.activityName][index]; const key = ActivityImgName[this.activityName][index]; const _asset = await $asset.loadAsset(path, SpriteFrame); this.loadedAssets.set(key, _asset); }
解决
标签:异步,const,activityName,index,await,asset,forEach From: https://www.cnblogs.com/kekit-rei/p/17847230.html