发送异步请求
async executewirelessscene(item) { let _this = this; let devices = _this.currentdeviceList; let Scenenumber = item.Slot; // console.log(Scenenumber); // console.log(devices.length); for (var i = 0, length = devices.length; i < length; i++) { var dName = devices[i].deviceName; var dzigbeeid = devices[i].zigbeeid; var dgroupid = devices[i].groupid; const param = { type: dgroupid, gatewayId: _this.gatewayID, zigbeeId: dzigbeeid, value: Scenenumber }; const result = await this.post( "/executewirelessscene", JSON.stringify(param) ); if (result.success) { this.$message({ message: dName + "指令下发成功", type: "success" }); } else { this.$message({ message: "failed!", type: "warning" }); } this.sleep(500);//for循环等待500ms } },
请求等待函数
//请求等待函数 async sleep(n) { var start = new Date().getTime(); while (true) { if (new Date().getTime() - start > n) { break; } } },