index.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <svg :class="svgClass" aria-hidden="true" v-on="$listeners">
  3. <use :xlink:href="iconName" />
  4. </svg>
  5. </template>
  6. <script>
  7. export default {
  8. name: 'SvgIcon',
  9. props: {
  10. iconClass: {
  11. type: String,
  12. required: true
  13. },
  14. className: {
  15. type: String,
  16. default: ''
  17. }
  18. },
  19. computed: {
  20. iconName() {
  21. return `#icon-${this.iconClass}`
  22. },
  23. svgClass() {
  24. if (this.className) {
  25. return 'svg-icon ' + this.className
  26. } else {
  27. return 'svg-icon'
  28. }
  29. },
  30. styleExternalIcon() {
  31. return {
  32. mask: `url(${this.iconClass}) no-repeat 50% 50%`,
  33. '-webkit-mask': `url(${this.iconClass}) no-repeat 50% 50%`
  34. }
  35. }
  36. }
  37. }
  38. </script>
  39. <style scoped>
  40. .svg-icon {
  41. width: 1.5em;
  42. height: 1.5em;
  43. vertical-align: -0.15em;
  44. fill: currentColor;
  45. overflow: hidden;
  46. }
  47. .svg-external-icon {
  48. background-color: currentColor;
  49. mask-size: cover!important;
  50. display: inline-block;
  51. }
  52. </style>