黑豹程序员-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>
相关推荐
夏梦春蝉1 小时前
ES6从入门到精通:模块化
前端·ecmascript·es6
拓端研究室2 小时前
视频讲解:门槛效应模型Threshold Effect分析数字金融指数与消费结构数据
前端·算法
工一木子3 小时前
URL时间戳参数深度解析:缓存破坏与前端优化的前世今生
前端·缓存
半点寒12W4 小时前
微信小程序实现路由拦截的方法
前端
某公司摸鱼前端5 小时前
uniapp socket 封装 (可拿去直接用)
前端·javascript·websocket·uni-app
要加油哦~5 小时前
vue | 插件 | 移动文件的插件 —— move-file-cli 插件 的安装与使用
前端·javascript·vue.js
小林学习编程5 小时前
Springboot + vue + uni-app小程序web端全套家具商场
前端·vue.js·spring boot
柳鲲鹏5 小时前
WINDOWS最快布署WEB服务器:apache2
服务器·前端·windows
weixin-a153003083166 小时前
【playwright篇】教程(十七)[html元素知识]
java·前端·html
ai小鬼头7 小时前
AIStarter最新版怎么卸载AI项目?一键删除操作指南(附路径设置技巧)
前端·后端·github