1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <template>
- <svg :class="svgClass" aria-hidden="true" v-on="$attrs">
- <use :xlink:href="iconName" />
- </svg>
- </template>
- <script setup lang="ts" name="SvgIcon">
- import { PropType, computed } from 'vue'
- const props = defineProps({
- // svg文件名
- iconClass: {
- type: String as PropType<string>,
- required: true
- },
- // 自定义类名
- className: {
- type: String as PropType<string>,
- default: ''
- }
- })
- const iconName = computed(() => `#icon-${props.iconClass}`)
- const svgClass = computed(() => {
- if (props.className) {
- return `svg-icon ${props.className}`
- } else {
- return 'svg-icon'
- }
- })
- </script>
- <style scoped>
- .svg-icon {
- width: 1em;
- height: 1em;
- overflow: hidden;
- vertical-align: -0.15em;
- fill: currentColor;
- }
- </style>
|