在使用 unplugin-auto-import 定义了 Element Plus 后,可以通过以下步骤在 Vue 3 项目中使用 Element Plus 的图标:

  1. 首先,确保已经安装了 Element Plus 和 @vue/compiler-sfc
npm install element-plus @vue/compiler-sfc
  1. 在项目的 main.js 文件中,导入 Element Plus 的样式和图标:
import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/lib/theme-chalk/index.css'
import 'element-plus/lib/theme-chalk/icon.css'

createApp(App)
  .use(ElementPlus)
  .mount('#app')
  1. 在组件中使用 Element Plus 的图标:
<template>
  <div>
    <el-button>
      <el-icon name='el-icon-search'></el-icon>
      Search
    </el-button>
  </div>
</template>

<script>
export default {
  name: 'MyComponent',
}
</script>

在上面的例子中,el-icon-search 是 Element Plus 中的一个图标名称,它将被渲染为一个 <i> 标签,应用了对应的 CSS 样式。你可以在 Element Plus 的官方文档中找到所有可用的图标名称。

这样,你就可以在 Vue 3 项目中使用 Element Plus 的图标了。


原文地址: https://www.cveoy.top/t/topic/piSx 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录