electricNo : "13675259" timers : [{startTime: "0:0:0", stopTime: "23:0:0"}, {startTime: "0:0:0", stopTime: "0:0:0"},…] 0 : {startTime: "0:0:0", stopTime: "23:0:0"} 1 : {startTime: "0:0:0", stopTime: "0:0:0"} 2 : {startTime: "0:0:0", stopTime: "0:0:0"} 3 : {startTime: "0:0:0", stopTime: "0:0:0"} timestamp : "1684891088000" type : 1 week : "7" 这是每天的数据,需要在页面中循环七次,得到七天的数据,并把每天数据中的timers的四条数据渲染到页面上。使用element grid组件 这是 async getPorts () { const outputArr = [] const promises = [] for (let i = 1; i <= 7; i++) { promises.push( electricQuery({ electricId: ELECTRIC_ID, commandKey: 15, queryMode: 1, week: i }).then(({ data }) => { if (data[0]) { outputArr.push(data[0]) } }) ) } await Promise.all(promises) return { data: outputArr } },js代码,如何修改,代码
时间: 2023-12-06 22:45:46 浏览: 190
你可以使用 `v-for` 指令循环七次,将每天的数据渲染到页面上。具体实现代码如下:
```html
<template>
<el-container>
<el-main>
<el-row>
<el-col v-for="(day, index) in data" :key="index">
<h3>Day {{ index + 1 }}</h3>
<el-card>
<div v-for="(timer, i) in day.timers" :key="i">
<p>Start Time: {{ timer.startTime }}</p>
<p>Stop Time: {{ timer.stopTime }}</p>
</div>
</el-card>
</el-col>
</el-row>
</el-main>
</el-container>
</template>
<script>
import { electricQuery } from '@/api/electric'
export default {
data() {
return {
data: []
}
},
async created() {
this.data = await this.getPorts()
},
methods: {
async getPorts() {
const outputArr = []
const promises = []
for (let i = 1; i <= 7; i++) {
promises.push(
electricQuery({
electricId: ELECTRIC_ID,
commandKey: 15,
queryMode: 1,
week: i
}).then(({ data }) => {
if (data[0]) {
outputArr.push(data[0])
}
})
)
}
await Promise.all(promises)
return outputArr
}
}
}
</script>
```
在页面中,我们通过 `v-for="(day, index) in data"` 循环七次,将每天的数据渲染到页面上。在每个循环中,我们使用 `v-for="(timer, i) in day.timers"` 将每天中的四条数据渲染到页面中。
阅读全文