zhongshujie
2 天以前 ce70bc450a2401997bb850f89f3c4dc0a23e0a72
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
<template>
  <!-- 如果是 Element UI 图标,保持不变 -->
  <i v-if="iconFileName.indexOf('el-icon-') === 0" :class="iconFileName" />
 
  <!-- 如果是 SVG 图标,进行改造 -->
  <svg v-else class="svg-icon" aria-hidden="true" v-on="$listeners">
    <!-- 
      :xlink:href 动态绑定图标ID
      注意:这里假设你的图标ID是 "icon-" + iconFileName
    -->
    <use class="useBox" :xlink:href="`#icon-${iconFileName}`" />
  </svg>
</template>
 
<script>
export default {
  name: 'SvgIcon',
  props: {
    iconFileName: {
      type: String,
      required: true
    },
  },
}
</script>
 
<style scoped>
.svg-icon {
  width: 1em;
  height: 1em;
  overflow: hidden;
  vertical-align: -0.15em;
  fill: currentColor;
}
</style>