svg-icon.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <template>
  2. <svg :class="svgClass" aria-hidden="true" v-on="$listeners">
  3. <use :xlink:href="iconName" />
  4. </svg>
  5. </template>
  6. <script>
  7. // doc: https://panjiachen.github.io/vue-element-admin-site/feature/component/svg-icon.html#usage
  8. function isExternal(path) {
  9. return /^(https?:|mailto:|tel:)/.test(path);
  10. }
  11. export default {
  12. name: 'SvgIcon',
  13. props: {
  14. iconClass: {
  15. type: String,
  16. required: true
  17. },
  18. className: {
  19. type: String,
  20. default: ''
  21. }
  22. },
  23. computed: {
  24. iconName() {
  25. return `#icon-${this.iconClass}`;
  26. },
  27. svgClass() {
  28. if (this.className) {
  29. return `svg-icon ${this.className}`;
  30. }
  31. return 'svg-icon';
  32. },
  33. }
  34. };
  35. </script>
  36. <style scoped>
  37. .svg-icon {
  38. width: 1em;
  39. height: 1em;
  40. vertical-align: -0.15em;
  41. fill: currentColor;
  42. overflow: hidden;
  43. }
  44. .svg-icon-set {
  45. width: 2em;
  46. height: 2em;
  47. vertical-align: -0.15em;
  48. fill: currentColor;
  49. overflow: hidden;
  50. }
  51. .svg-external-icon {
  52. background-color: currentColor;
  53. mask-size: cover !important;
  54. display: inline-block;
  55. }
  56. </style>