index.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <div class="icon-body">
  3. <el-input v-model="name" style="position: relative;" clearable placeholder="请输入图标名称" @clear="filterIcons" @input.native="filterIcons">
  4. <i slot="suffix" class="el-icon-search el-input__icon" />
  5. </el-input>
  6. <div class="icon-list">
  7. <div v-for="(item, index) in iconList" :key="index" @click="selectedIcon(item)">
  8. <svg-icon :icon-class="item" style="height: 30px;width: 16px;" />
  9. <span>{{ item }}</span>
  10. </div>
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. import icons from './requireIcons'
  16. export default {
  17. name: 'IconSelect',
  18. data() {
  19. return {
  20. name: '',
  21. iconList: icons
  22. }
  23. },
  24. methods: {
  25. filterIcons() {
  26. this.iconList = icons
  27. if (this.name) {
  28. this.iconList = this.iconList.filter(item => item.includes(this.name))
  29. }
  30. },
  31. selectedIcon(name) {
  32. this.$emit('selected', name)
  33. document.body.click()
  34. },
  35. reset() {
  36. this.name = ''
  37. this.iconList = icons
  38. }
  39. }
  40. }
  41. </script>
  42. <style rel="stylesheet/scss" lang="scss" scoped>
  43. .icon-body {
  44. width: 100%;
  45. padding: 10px;
  46. .icon-list {
  47. height: 200px;
  48. overflow-y: scroll;
  49. div {
  50. height: 30px;
  51. line-height: 30px;
  52. margin-bottom: -5px;
  53. cursor: pointer;
  54. width: 33%;
  55. float: left;
  56. }
  57. span {
  58. display: inline-block;
  59. vertical-align: -0.15em;
  60. fill: currentColor;
  61. overflow: hidden;
  62. }
  63. }
  64. }
  65. </style>