You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
777 B
Vue
42 lines
777 B
Vue
<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>
|