index.vue 692 Bytes
Newer Older
Pan's avatar
Pan committed
1
<template>
Pan's avatar
Pan committed
2
  <svg :class="svgClass" aria-hidden="true" v-on="$listeners">
花裤衩's avatar
花裤衩 committed
3
    <use :xlink:href="iconName" />
Pan's avatar
Pan committed
4 5 6 7 8
  </svg>
</template>

<script>
export default {
9
  name: 'SvgIcon',
Pan's avatar
Pan committed
10 11 12 13 14 15
  props: {
    iconClass: {
      type: String,
      required: true
    },
    className: {
16 17
      type: String,
      default: ''
Pan's avatar
Pan committed
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
    }
  },
  computed: {
    iconName() {
      return `#icon-${this.iconClass}`
    },
    svgClass() {
      if (this.className) {
        return 'svg-icon ' + this.className
      } else {
        return 'svg-icon'
      }
    }
  }
}
</script>

<style scoped>
.svg-icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}
</style>