Advertisement
yxq0921

Untitled

Mar 16th, 2024 (edited)
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.   <svg aria-hidden="true" class="svg-icon" :style="'width:' + size + ';height:' + size">
  3.     <use :xlink:href="symbolId" :fill="color" />
  4.   </svg>
  5. </template>
  6.  
  7. <script setup lang="ts">
  8. const props = defineProps({
  9.   prefix: {
  10.     type: String,
  11.     default: 'icon'
  12.   },
  13.   iconClass: {
  14.     type: String,
  15.     required: false,
  16.     default: ''
  17.   },
  18.   color: {
  19.     type: String,
  20.     default: ''
  21.   },
  22.   size: {
  23.     type: String,
  24.     default: '1em'
  25.   }
  26. })
  27.  
  28. const symbolId = computed(() => `#${props.prefix}-${props.iconClass}`)
  29. </script>
  30.  
  31. <style scoped>
  32. .svg-icon {
  33.   display: inline-block;
  34.   width: 1em;
  35.   height: 1em;
  36.   overflow: hidden;
  37.   vertical-align: -0.15em; /* 因icon大小被设置为和字体大小一致,而span等标签的下边缘会和字体的基线对齐,故需设置一个往下的偏移比例,来纠正视觉上的未对齐效果 */
  38.   outline: none;
  39.   fill: currentcolor; /* 定义元素的颜色,currentColor是一个变量,这个变量的值就表示当前元素的color值,如果当前元素未设置color值,则从父元素继承 */
  40. }
  41. </style>
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement