<template> <div class="container"> <div v-for="(item, index) of device" class="device" :key="item.title" :style="{ width: index === 0 ? '51%' : '50%' }" > <div><svg-icon :icon-class="item.icon"></svg-icon></div> <div class="content"> <div>{{ item.title }}</div> <div>{{ item.count }}</div> </div> </div> </div> </template> <script> import SvgIcon from "@/components/SvgIcon"; import { getDeviceInfo } from "@/api/cockpit/cockpit"; export default { name: "deviceList", components: { SvgIcon, }, data() { return { device: [ { title: "设备总数", count: "", icon: "device-count", type: "total", }, { title: "IOT设备数量", count: "", icon: "device-count", type: "iot", }, { title: "IOT设备在线率", count: "", icon: "device-fund", type: "iotRatio", }, ], }; }, methods: { fetchData() { // 获取设备总数、IOT设备数量、IOT设备在线率 getDeviceInfo().then((res) => { for (var i = 0; i < this.device.length; i++) { for (var device in res.data) { if(this.device[i].type === device) { this.device[i].count = res.data[device] } } } }); }, }, created() { this.fetchData(); }, }; </script> <style lang="scss" scoped> .container { display: flex; flex-wrap: wrap; justify-content: center; .device { width: 50%; display: flex; justify-content: center; font-size: 20px; ::v-deep .svg-icon { width: 40px; height: 40px; color: rgb(64, 158, 255); } .content { margin-left: 10px; } } } </style>