iconSvg.vue 698 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <template>
  2. <svg class="svg-icon" aria-hidden="true">
  3. <image v-if="svgHref" :xlink:href="svgHref" />
  4. <use v-else :xlink:href="_iconName"/>
  5. <!-- 使用 链接 加载 svg-->
  6. </svg>
  7. </template>
  8. <script>
  9. export default {
  10. name: 'SvgIcon',
  11. props: {
  12. iconClass: {
  13. type: String,
  14. default: '',
  15. },
  16. svgHref: {
  17. type: String,
  18. default: '',
  19. },
  20. },
  21. computed: {
  22. _iconName () {
  23. return `#icon-${this.iconClass}`
  24. },
  25. },
  26. }
  27. </script>
  28. <style scoped>
  29. .svg-icon {
  30. width: 1em;
  31. height: 1em;
  32. vertical-align: -0.15em;
  33. fill: currentColor;
  34. overflow: hidden;
  35. }
  36. .svg-icon image {
  37. width: 100%;
  38. height: 100%;
  39. fill: currentColor;
  40. }
  41. </style>