当我使用element-plus创建图标组件时,我使用unplugin图标和unplugin自动导入来自动导入图标,例如我使用<el-icon><i-ep-monitor />< /el-icon>导入图标组件。现在我有了一个需求,我有一个数组,它存储一些字符串,比如['i-ep-avatar', 'i-ep-cellphone', 'i-ep-apple'],现在我可以传递什么方法,将这个数组中的字符串转换成组件,然后动态地将它们添加到vue模板中。我希望得到你的帮助。
<template>
<el-icon>
<i-ep-monitor />
</el-icon>
</template>当我这样写时,它可以正常地导入。
<template>
<el-icon>
{How should I dynamically generate a component like <i-ep-monitor /> from the string content in the array?}
</el-icon>
</template>发布于 2022-08-15 17:12:09
你可以使用<component>
详细信息:https://vuejs.org/api/built-in-special-elements.html#component
示例:
<template>
<el-icon>
<component :is="myIcon"/>
</el-icon>
</template>其中myIcon将返回一个类似于i-ep-monitor的字符串
https://stackoverflow.com/questions/73364176
复制相似问题