MeterGroup

MeterGroup 在已知范围内显示标量测量值。


import MeterGroup from 'primevue/metergroup';

MeterGroup 需要一个 value 作为要显示的数据,其中集合中的每个项目都应该是一种 MeterItem 类型。

  1. 已用空间 (15%)

<MeterGroup :value="value" />

向数组中添加更多项目会在组中显示仪表。

  1. 应用 (16%)
  2. 消息 (8%)
  3. 媒体 (24%)
  4. 系统 (10%)

<MeterGroup :value="value" />

图标可以显示在标签旁边,而不是默认的标记。

  1. 应用 (16%)
  2. 消息 (8%)
  3. 媒体 (24%)
  4. 系统 (10%)

<MeterGroup :value="value" />

标签相对于仪表的位置使用 labelPosition 属性定义。标签的默认方向是水平的,垂直替代方案可通过 labelOrientation 选项获得。

  1. 应用 (16%)
  2. 消息 (8%)
  3. 媒体 (24%)
  4. 系统 (10%)

<MeterGroup :value="value" labelPosition="start" labelOrientation="vertical" />

MeterGroup 的布局通过 orientation 属性配置,该属性接受 horizontalvertical 作为可用选项。

  1. 应用 (24%)
  2. 消息 (16%)
  3. 媒体 (24%)
  4. 系统 (12%)

<MeterGroup :value="value" orientation="vertical" labelOrientation="vertical" />

边界通过 minmax 值配置,它们的默认值分别为 0 和 100。

  1. 应用 (8%)
  2. 消息 (4%)
  3. 媒体 (12%)
  4. 系统 (5%)

<MeterGroup :value="value" :max="200"  />

MeterGroup 提供对标签、仪表项以及仪表周围内容的模板支持。

应用25%
消息15%
媒体20%
系统10%
存储70%1TB

<MeterGroup :value="value" labelPosition="start">
    <template #label="{ value }">
        <div class="flex flex-wrap gap-4">
            <template v-for="val of value" :key="val.label">
                <Card class="flex-1 border border-surface shadow-none">
                    <template #content>
                        <div class="flex justify-between gap-8">
                            <div class="flex flex-col gap-1">
                                <span class="text-surface-500 dark:text-surface-400 text-sm">{{ val.label }}</span>
                                <span class="font-bold text-lg">{{ val.value }}%</span>
                            </div>
                            <span class="w-8 h-8 rounded-full inline-flex justify-center items-center text-center" :style="{ backgroundColor: `${val.color1}`, color: '#ffffff' }">
                                <i :class="val.icon" />
                            </span>
                        </div>
                    </template>
                </Card>
            </template>
        </div>
    </template>
    <template #meter="slotProps">
        <span :class="slotProps.class" :style="{ background: `linear-gradient(to right, ${slotProps.value.color1}, ${slotProps.value.color2})`, width: slotProps.size }" />
    </template>
    <template #start="{ totalPercent }">
        <div class="flex justify-between mt-4 mb-2 relative">
            <span>Storage</span>
            <span :style="{ width: totalPercent + '%' }" class="absolute text-right">{{ totalPercent }}%</span>
            <span class="font-medium">1TB</span>
        </div>
    </template>
    <template #end>
        <div class="flex justify-between mt-4">
            <Button label="Manage Storage" outlined size="small" />
            <Button label="Update Plan" size="small" />
        </div>
    </template>
</MeterGroup>

屏幕阅读器

MeterGroup 组件使用 meter 角色,以及 aria-valueminaria-valuemaxaria-valuenow 属性。可以使用 aria-labelledby 属性定义描述组件的值。

键盘支持

组件不包含任何交互元素。