黑豹程序员-ElementPlus选择图标器

ElementPlus组件提供了很多图标svg

如何在你的系统中,用户可以使用呢?

这就是图标器,去调用ElementPlus的icon组件库,展示到页面,用户选择,返回选择的组件名称。

效果

代码

bash 复制代码
<template>
  <el-input @click="iconDialogVisible = true" v-model="currentIconName">
  </el-input>
  <el-dialog
      v-model="iconDialogVisible"
      title="请选择图标"
      width="80%"
      :before-close="handleClose"
      @open="beforeOpen"
  >
    <div style="display: flex;flex-wrap: wrap">
      <div v-for="(name,index) in icons" :index="index" :key="index" style="cursor: pointer; padding: 5px; border: 1px solid rgb(227,232,232);"
           :class="currentIconName === name ? 'red' : ''"
           @click="currentIconName = name"
      >
        <component :is="name" style="width: 1.2rem;height: 1.2rem"></component>
      </div>
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="iconDialogVisible = false">取消</el-button>
        <el-button type="primary" @click="handleOk"
        >确定</el-button
        >
      </span>
    </template>
  </el-dialog>

</template>

<script>
import * as ElIcons from '@element-plus/icons-vue'
import {reactive, ref, toRefs, watch} from "vue";

export default {
  components: {
    ...ElIcons
  },
  name: "Naruto-Icon.vue",
  emits: ['update:iconName'],
  props: {
    iconName: {
      type: String
    }
  },
  setup(props, context) {
    const getData = () => {
      let icons = []
      for (const name in ElIcons) {
        icons.push(name)
      }
      return icons
    }
    const handleClose = () => {
      iconList.iconDialogVisible = false;
    }
    const beforeOpen = () => {

    }
    const handleOk = () => {
      context.emit(`update:iconName`, iconList.currentIconName);
      handleClose();
    }
    const iconList = reactive({
      icons: getData(),
      iconDialogVisible: false,
      currentIconName: 'Aim'
    })
    watch(() => props.iconName,(val) => {
      iconList.currentIconName = val;
    })
    return {
      ...toRefs(iconList),
      handleClose,
      beforeOpen,
      handleOk
    }
  }
}
</script>

<style scoped>
.red{
  background-color: palevioletred;
  color: white;
}
</style>
相关推荐
_丿丨丨_5 小时前
XSS(跨站脚本攻击)
前端·网络·xss
古月-一个C++方向的小白5 小时前
C++11之lambda表达式与包装器
开发语言·c++
天天进步20155 小时前
前端安全指南:防御XSS与CSRF攻击
前端·安全·xss
沐知全栈开发5 小时前
Eclipse 生成 jar 包
开发语言
呼啦啦呼啦啦啦啦啦啦6 小时前
利用pdfjs实现的pdf预览简单demo(包含翻页功能)
android·javascript·pdf
杭州杭州杭州6 小时前
Python笔记
开发语言·笔记·python
tanyongxi667 小时前
C++ AVL树实现详解:平衡二叉搜索树的原理与代码实现
开发语言·c++
拾光拾趣录7 小时前
括号生成算法
前端·算法
阿葱(聪)8 小时前
java 在k8s中的部署流程
java·开发语言·docker·kubernetes
拾光拾趣录8 小时前
requestIdleCallback:让你的网页如丝般顺滑
前端·性能优化