当前位置:   article > 正文

Ant Design of Vue图标选择器_ant 图标选择器

ant 图标选择器

看了一下antDesign并没有图标选择的组件,在网上查找了一下资料发现这篇文章已经实现了下拉选择图标的需求;

antd vue图标选择器icon-default.png?t=M666https://blog.csdn.net/a2925447584/article/details/116702831

但是实底图标,线性图标,双色图标全部混在了一起,功能虽然已经实现了,但后期用户查找起来比较麻烦,于是打算自己手动写一个图标选择器,实现效果如下:

可对图标风格进行切换 

 

一、全局图标

main.js中引入全部图标

  1. import { createApp } from 'vue';
  2. import App from './App.vue';
  3. import Antd from 'ant-design-vue';
  4. import 'ant-design-vue/dist/antd.css';
  5. import * as antIcons from "@ant-design/icons-vue";
  6. import RouterIndex from './router/index';
  7. import axios from 'axios';
  8. import VueAxios from 'vue-axios';
  9. const app = createApp(App).use(Antd);
  10. app.use(RouterIndex);
  11. // 注册组件
  12. Object.keys(antIcons).forEach(key => {
  13. app.component(key, antIcons[key])
  14. })
  15. // 添加到全局
  16. app.config.globalProperties.$antIcons = antIcons
  17. app.mount("#app");

二、图标选择器组件

iconPicker组件

  1. <template>
  2. <a-radio-group v-model:value="value1" button-style="solid">
  3. <a-radio-button value="1">线框风格</a-radio-button>
  4. <a-radio-button value="2">实底风格</a-radio-button>
  5. <a-radio-button value="3">双色风格</a-radio-button>
  6. </a-radio-group>
  7. <div style="margin-top: 15px;">
  8. <span v-for="(item,i) in iconList" class="icons-list">
  9. <span v-if="value1==1">
  10. <component class="icon" @click="sendMsg(iconList[i])" v-if="iconList[i].indexOf('Outlined')>0" :is="$antIcons[iconList[i]]" />
  11. </span>
  12. <span v-if="value1==2">
  13. <component class="icon" @click="sendMsg(iconList[i])" v-if="iconList[i].indexOf('Filled')>0" :is="$antIcons[iconList[i]]" />
  14. </span>
  15. <span v-if="value1==3">
  16. <component class="icon" @click="sendMsg(iconList[i])" v-if="iconList[i].indexOf('TwoTone')>0" :is="$antIcons[iconList[i]]" />
  17. </span>
  18. </span>
  19. </div>
  20. </template>
  21. <script>
  22. import {
  23. defineComponent
  24. } from 'vue';
  25. import {
  26. HomeOutlined,
  27. SettingFilled,
  28. SmileOutlined,
  29. SyncOutlined,
  30. LoadingOutlined,
  31. } from '@ant-design/icons-vue';
  32. import iconList from '../iconPicker/icons.json'
  33. export default defineComponent({
  34. components: {
  35. HomeOutlined,
  36. SettingFilled,
  37. SmileOutlined,
  38. SyncOutlined,
  39. LoadingOutlined,
  40. },
  41. data() {
  42. return {
  43. iconList: iconList,
  44. value1: "1",
  45. }
  46. },
  47. methods:{
  48. sendMsg:function(iconText) {
  49. //func: 是父组件指定的传数据绑定的函数,this.msg:子组件给父组件传递的数据
  50. this.$emit('func', iconText)
  51. }
  52. },
  53. created() {
  54. }
  55. });
  56. </script>
  57. <style scoped>
  58. .icons-list :deep(.anticon) {
  59. margin-right: 6px;
  60. font-size: 24px;
  61. }
  62. .icon:hover {
  63. background-color: #1890ff;
  64. color: white;
  65. }
  66. </style>

需引入的icons.json文件

  1. [
  2. "AccountBookFilled",
  3. "AccountBookOutlined",
  4. "AccountBookTwoTone",
  5. "AimOutlined",
  6. "AlertFilled",
  7. "AlertOutlined",
  8. "AlertTwoTone",
  9. "AlibabaOutlined",
  10. "AlignCenterOutlined",
  11. "AlignLeftOutlined",
  12. "AlignRightOutlined",
  13. "AlipayCircleFilled",
  14. "AlipayCircleOutlined",
  15. "AlipayOutlined",
  16. "AlipaySquareFilled",
  17. "AliwangwangFilled",
  18. "AliwangwangOutlined",
  19. "AliyunOutlined",
  20. "AmazonCircleFilled",
  21. "AmazonOutlined",
  22. "AmazonSquareFilled",
  23. "AndroidFilled",
  24. "AndroidOutlined",
  25. "AntCloudOutlined",
  26. "AntDesignOutlined",
  27. "ApartmentOutlined",
  28. "ApiFilled",
  29. "ApiOutlined",
  30. "ApiTwoTone",
  31. "AppleFilled",
  32. "AppleOutlined",
  33. "AppstoreAddOutlined",
  34. "AppstoreFilled",
  35. "AppstoreOutlined",
  36. "AppstoreTwoTone",
  37. "AreaChartOutlined",
  38. "ArrowDownOutlined",
  39. "ArrowLeftOutlined",
  40. "ArrowRightOutlined",
  41. "ArrowUpOutlined",
  42. "ArrowsAltOutlined",
  43. "AudioFilled",
  44. "AudioMutedOutlined",
  45. "AudioOutlined",
  46. "AudioTwoTone",
  47. "AuditOutlined",
  48. "BackwardFilled",
  49. "BackwardOutlined",
  50. "BankFilled",
  51. "BankOutlined",
  52. "BankTwoTone",
  53. "BarChartOutlined",
  54. "BarcodeOutlined",
  55. "BarsO
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/113104
推荐阅读
相关标签
  

闽ICP备14008679号