vue3vite引入elementui图标
时间: 2023-10-14 13:16:12 浏览: 106
在 Vue3 + Vite 项目中引入 Element UI 的图标可以按照以下步骤进行:
1. 首先,确保您已经按照 Element UI 官方指南成功安装 Element UI。
2. 在 `main.js` 中引入 Element UI 的 CSS 样式文件和 JavaScript 文件:
```javascript
import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/lib/theme-chalk/index.css'
const app = createApp(App)
app.use(ElementPlus)
app.mount('#app')
```
3. 在 `vite.config.js` 中配置 Element UI 的图标路径:
```javascript
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
// 配置 Element UI 图标路径
'@element-plus/icons': 'element-plus/packages/theme-chalk/src/icons',
},
},
})
```
4. 在需要使用图标的组件中,使用 `el-icon` 标签加上相应的图标类名即可,例如:
```html
<el-icon name="el-icon-search"></el-icon>
```
其中,`name` 属性的值是 Element UI 图标库中对应图标的类名。
希望这些步骤能够帮助您成功引入 Element UI 的图标。
阅读全文
相关推荐














