icon-svg.vue 862 B

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