Ant Design of Vue Icon 图标列表

7 篇文章 0 订阅
1 篇文章 0 订阅

拷贝插件

yarn add vue-clipboard2

// main.js
//复制到粘贴板插件
import VueClipboard from 'vue-clipboard2'
VueClipboard.config.autoSetContainer = true
Vue.use(VueClipboard)

图标列表

// /src/views/icons.vue
<template>
  <div>
    <a-radio-group :value="theme" @change="handleThemeChange">
      <a-radio-button value="gold">
        <a-icon type="gold" />
        <span style="margin-left:8px">全部</span>
      </a-radio-button>
      <a-radio-button value="outline">
        <a-icon type="outline" />
        <span style="margin-left:8px">线框风格</span>
      </a-radio-button>
      <a-radio-button value="fill">
        <a-icon type="fill" />
        <span style="margin-left:8px">实体分格</span>
      </a-radio-button>
      <a-radio-button value="twotone">
        <a-icon type="twotone" />
        <span style="margin-left:8px">双色风格</span>
      </a-radio-button>
    </a-radio-group>

    <ul class="icon-list">
      <li v-for="(item, index) in iconList" :key="index" @click="copy(item)">
        <a-icon :type="item.name" :theme="getTheme(item)" />
        <span>{{ item.name }}</span>
      </li>
    </ul>
    <a-back-top />
  </div>
</template>
<script>
import VueIcon from '@ant-design/icons-vue'
export default {
  name: 'icons',
  data() {
    return {
      icons: VueIcon.definitions.collection,
      iconList: [],
      theme: 'outline'
    }
  },
  created() {
    this.getThemeIcons()
  },
  methods: {
    copy(icon) {
      let text = this.getContent(icon)
      let message = this.$message
      this.$copyText(text).then(
        function(e) {
          message.success(text + '  复制成功 🎉', 5)
        },
        function(e) {
          message.error(text, 5)
        }
      )
    },
    getContent(icon) {
      let theme = this.getTheme(icon)
      if (theme === 'outlined') return `<a-icon type="${icon.name}"  />`
      return `<a-icon type="${icon.name}" theme="${theme}" />`
    },
    getThemeIcons() {
      if (this.theme == 'gold') this.iconList = Object.values(this.icons).filter(t => t)
      else this.iconList = Object.values(this.icons).filter(t => t.theme == this.theme)
    },
    handleThemeChange(e) {
      this.theme = e.target.value
      this.getThemeIcons()
    },
    getTheme(item) {
      if (item.theme == 'outline') return 'outlined'
      if (item.theme == 'fill') return 'filled'
      if (item.theme == 'twotone') return 'twoTone'
    }
  }
}
</script>

<style lang="scss">
.icon-list {
  margin: 10px 0;
  list-style: none;

  li {
    float: left;
    width: 120px;
    text-align: center;
    list-style: none;
    cursor: pointer;
    height: 100px;
    color: #555;
    transition: color 0.3s ease-in-out, background-color 0.3s ease-in-out;
    position: relative;
    margin: 3px 0;
    border-radius: 4px;
    background-color: #fff;
    overflow: hidden;
    padding: 10px 0 0;
    &:hover {
      background-color: #1890ff;
      color: #fff;
    }
    span {
      display: block;
      text-align: center;
      transform: scale(0.83);
      font-family: Lucida Console, Consolas;
      white-space: nowrap;
    }
    .anticon {
      font-size: 36px;
      margin: 12px 0 8px;
      transition: transform 0.3s ease-in-out;
      will-change: transform;
    }
  }
}
</style>

页面效果

线框图标
实体图标
双色图标

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hobtdto

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值