关于前端:vue3中如何引入elementicon并使用

42次阅读

共计 1100 个字符,预计需要花费 3 分钟才能阅读完成。

简略来说,步骤就是:
装置——注册——按需引入——应用

装置

# NPM
$ npm install @element-plus/icons-vue
# Yarn
$ yarn add @element-plus/icons-vue
# pnpm
$ pnpm install @element-plus/icons-vue

注册

您须要从 @element-plus/icons-vue 中导入所有图标并进行全局注册。

import * as ElementPlusIconsVue from '@element-plus/icons-vue'

const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {app.component(key, component)
}

按需引入

<script>
import {ArrowDown} from "@element-plus/icons-vue";

export default {
  name: "APP",
  components: {ArrowDown}
}
</script>

接下来就能够应用了~

应用

<div class="flex flex-wrap items-center">
        <el-dropdown>
          <span class="el-dropdown-link">
            Dropdown List
            <el-icon class="el-icon--right">
              <arrow-down/>
            </el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item>Action 1</el-dropdown-item>
              <el-dropdown-item>Action 2</el-dropdown-item>
              <el-dropdown-item>Action 3</el-dropdown-item>
              <el-dropdown-item disabled>Action 4</el-dropdown-item>
              <el-dropdown-item divided>Action 5</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
<style scoped>
.example-showcase .el-dropdown-link {
  cursor: pointer;
  color: var(--el-color-primary);
  display: flex;
  align-items: center;
}
</style>

实例成果

正文完
 0