index.vue 824 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <!-- 添加fill -->
  3. <svg
  4. :class="getClassName"
  5. aria-hidden="true"
  6. >
  7. <use
  8. :xlink:href="getName"
  9. />
  10. </svg>
  11. </template>
  12. <script>
  13. export default {
  14. name: 'IconSvg',
  15. props: {
  16. name: {
  17. type: String,
  18. required: true
  19. },
  20. className: {
  21. type: String,
  22. default: ''
  23. }
  24. },
  25. computed: {
  26. getName () {
  27. return `#icon-${this.name}`
  28. },
  29. getClassName () {
  30. return [
  31. 'icon-svg',
  32. `icon-svg__${this.name}`,
  33. this.className && /\S/.test(this.className) ? `${this.className}` : ''
  34. ]
  35. }
  36. }
  37. }
  38. </script>
  39. <style scoped>
  40. .icon-svg {
  41. width: 18px;
  42. height: 18px;
  43. vertical-align: middle;
  44. fill: currentColor;
  45. overflow: hidden;
  46. mask-size: cover!important;
  47. display: inline-block;
  48. }
  49. </style>