JS For循环中让异步请求执行完之后再执行后续步骤

如下所示

getPlatformList(tenantId) {
      allPlatform(tenantId).then(async response => {
        this.platList = response.data;
        // 循环
        for (let item of this.platList) {
        // 异步
          await getMenuListByPlatform(item.platformId).then(res => {
            item.treeData = this.handleTree(res.data.menus, 'menuId')
            item.treeIdList = res.data.menuIds
          })
        }
        //在循环后在执行以下代码,可以解决Vue中组件提前渲染
        this.menuDrawer = true
      });
    },

你可能感兴趣的:(javascript,前端,vue.js)