Loading

vue3 封装一个组件来使用element+的 icon+text

使用element-plus时,遇到icon图标与文字不对齐的情况,可以使用flex布局使其对齐,设置相同字体尺寸使其美观。
为方便使用,封装一下:

新建一个vue文件IconText.vue

<script setup>
import { computed } from '@vue/reactivity'
defineProps(['icon', 'text'])
</script>
<template>
    <span class="align">
        <el-icon>
            <component :is="icon"></component>
        </el-icon>
        <span class="mar">{{ text }}</span>
    </span>
</template>
<style scoped>
.align{
    display: flex;
    justify-content: center;
    align-items: center;
}
.mar{
    margin-left: 3px;
}
</style>

使用

导入

import IconText from "../components/IconText.vue"	

在父组件中使用它:

<IconText icon="DataAnalysis" text="数据统计"></IconText>

组件接收两个参数,分别是element+提供的图标Name,和紧跟的文字。

posted @ 2022-07-27 09:48  sq800  阅读(628)  评论(0编辑  收藏  举报