fuchengshen
2022-06-14 78a51aa7f5e7bd8b16020ace4d471b745cd65604
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<template>
    <svg :class="svgClass" :style="style" aria-hidden="true">
        <use :xlink:href="iconName" />
    </svg>
</template>
 
<script lang="ts">
import { computed, defineComponent, ref } from "vue";
import { isNumber } from "/@/cool/utils";
 
export default defineComponent({
    name: "icon-svg",
 
    cool: {
        global: true
    },
 
    props: {
        name: {
            type: String
        },
        className: {
            type: String
        },
        size: {
            type: [String, Number]
        }
    },
 
    setup(props) {
        const style = ref<any>({
            fontSize: isNumber(props.size) ? props.size + "px" : props.size
        });
 
        const iconName = computed<string>(() => `#icon-${props.name}`);
        const svgClass = computed<Array<string>>(() => {
            return ["icon-svg", `icon-svg__${props.name}`, String(props.className || "")];
        });
 
        return {
            style,
            iconName,
            svgClass
        };
    }
});
</script>
 
<style scoped>
.icon-svg {
    width: 1em;
    height: 1em;
    vertical-align: -0.15em;
    fill: currentColor;
    overflow: hidden;
}
</style>