SvgIcon.vue 918 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <template>
  2. <svg :class="svgClass" aria-hidden="true">
  3. <use :xlink:href="iconName" />
  4. </svg>
  5. </template>
  6. <script lang="ts">
  7. export default defineComponent({
  8. props: {
  9. iconClass: {
  10. type: String,
  11. required: true
  12. },
  13. className: {
  14. type: String,
  15. default: ''
  16. }
  17. // color: {
  18. // type: String,
  19. // default: '#889aa4',
  20. // },
  21. },
  22. setup(props) {
  23. return {
  24. iconName: computed(() => `#icon-${props.iconClass}`),
  25. svgClass: computed(() => {
  26. if (props.className) {
  27. return `svg-icon ${props.className}`
  28. }
  29. return 'svg-icon'
  30. })
  31. }
  32. }
  33. })
  34. </script>
  35. <style scope lang="scss">
  36. .sub-el-icon,
  37. .nav-icon {
  38. display: inline-block;
  39. font-size: 15px;
  40. margin-right: 12px;
  41. position: relative;
  42. }
  43. .svg-icon {
  44. width: 1em;
  45. height: 1em;
  46. position: relative;
  47. fill: currentColor;
  48. vertical-align: -2px;
  49. }
  50. </style>