参考: https://blog.csdn.net/weixin_44976833/article/details/106210269

            // 获取房间号 
            let roomalls = []
            for (let i = 0; i < res.data.room_device_relations.length; i++) {
                roomalls.push(getrom(res.data.room_device_relations[i].room_id))    //  返回的是 [Promise] 数组
            }
            console.log(roomalls) 
            Promise.all(roomalls).then(res => {
                console.log(res)
                setRoomalls(res)
            })

   
  // 可以用  async   await  变同步的方法
    const getrom = async (val) => {
        const msg = await roomsthing(val)
        console.log(msg)
        return msg.data.room_no
    }

 业务场景    在   一个请求回来的数据中有个数组  多项 的id      要用这些  id   在   去依次请求 接口    就需要先在循环中 用数组 保存 每一个 promers  然后 在用 promise.all 在  把结果 列出来    

相关文章:

  • 2022-12-23
  • 2021-09-13
  • 2021-05-02
  • 2021-11-20
  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
  • 2021-09-05
猜你喜欢
  • 2021-07-27
  • 2021-08-11
  • 2021-07-24
  • 2022-12-23
  • 2021-09-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案