数组里有数据,但无法遍历且数组长度为0,或数组带有__ob__: Observer,如何解决?
一般这种情况是异步的问题,不信可以在setTimeout函数里打印看看,接下来步入正题:
async getData() {
let params = [{voltageClass: '110kV'}, {voltageClass: '220kV'}, {voltageClass: '500kV'}]
let dataArr = []
let voltageClass = []
let max = [100, 100, 100]
let promiseArr = []
params.map(item => {
voltageClass.push(item.voltageClass)
//selectDiffSubInfo 后端接口请求数据
promiseArr.push(selectDiffSubInfo(item))
})
//Promise获取返回结果
let resArr = await Promise.all(promiseArr)
resArr.map(item => {
dataArr.push(item.data.substation)
})
//调用绘制echart图
this.init_powerElectricity(voltageClass, dataArr, max)
},