index.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. if (this.name) {
  27. this.iconList = this.iconList.filter(item => item.includes(this.name))
  28. } else {
  29. this.iconList = icons
  30. }
  31. },
  32. selectedIcon(name) {
  33. this.$emit('selected', name)
  34. document.body.click()
  35. },
  36. reset() {
  37. this.name = ''
  38. this.iconList = icons
  39. }
  40. }
  41. }
  42. </script>
  43. <style rel="stylesheet/scss" lang="scss" scoped>
  44. .icon-body {
  45. width: 100%;
  46. padding: 10px;
  47. .icon-list {
  48. height: 200px;
  49. overflow-y: scroll;
  50. div {
  51. height: 30px;
  52. line-height: 30px;
  53. margin-bottom: -5px;
  54. cursor: pointer;
  55. width: 33%;
  56. float: left;
  57. }
  58. span {
  59. display: inline-block;
  60. vertical-align: -0.15em;
  61. fill: currentColor;
  62. overflow: hidden;
  63. }
  64. }
  65. }
  66. </style>