-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVLocalSvgIcon.vue
64 lines (58 loc) · 1.47 KB
/
VLocalSvgIcon.vue
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
58
59
60
61
62
63
64
<!--
* @Description: svg组件,在src/assets/icons/svg文件夹下添加.svg文件后调用该组件即可使用
* @Tips: 亲,记得补全功能描述哦~ (ღ˘⌣˘ღ)
* @Author: Mr.Mikey
* @Contact: 1303232158@qq.com
* @Date: 2022-07-14 00:31:13
* @LastEditors: Mr.Mikey
* @LastEditTime: 2023-06-20 16:41:14
* @FilePath: \vue3-admin\src\components\common\VLocalSvgIcon.vue
-->
<template>
<div class="v-local-svg-icon">
<!-- svg格式渲染svg标签 -->
<svg :style="setIconSvgStyle" aria-hidden="true" class="local-svg-icon">
<use :xlink:href="iconName" />
</svg>
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue'
const props = defineProps({
// 对应assets/icons/svg目录下的文件名
name: {
type: String,
required: true,
},
// svg 大小
size: {
type: Number,
default: () => 14,
},
// svg 颜色
color: {
type: String,
},
})
// 生成iconName
const iconName = computed(() => `#icon-${props.name}`)
// 设置图标样式
const setIconSvgStyle = computed(() => {
return `font-size: ${props.size}px;color: ${props.color};`
})
</script>
<style lang="scss" scoped>
.local-svg-icon {
width: 1em;
height: 1em;
vertical-align: -0.15em;
fill: currentColor;
overflow: hidden;
outline: none;
}
.local-svg-external-icon {
background-color: currentColor;
mask-size: cover !important;
display: inline-block;
}
</style>