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
| <template>
| <svg :class="classList" aria-hidden="true">
| <use :xlink:href="iconName" :fill="color" />
| </svg>
| </template>
| <script setup>
| import { computed } from 'vue';
| const props = defineProps({
| className: {
| type: String,
| default: ''
| },
| iconClass: {
| type: String,
| required: true
| },
| color: {
| type: String,
| default: '#409eff'
| },
| size: {
| type: String,
| default: '20px'
| }
| });
| const classList = computed(() => {
| return ['icon', props.className || ''];
| });
| const iconName = computed(() => {
| return `#${props.iconClass}`;
| });
| </script>
| <style scoped>
| .icon {
| /* v-bind是Vue3才支持的功能,可以将CSS的值与js的值绑定 */
| width: v-bind('props.size');
| height: v-bind('props.size');
| position: relative;
| vertical-align: -2px;
| fill: currentColor;
| }
| </style>
|
|