svg组件

2022-07-25 14:27:53

在main.js中引入

import './icons'

在components的SvgIcon文件,在此文件夹中写svg组件
在这里插入图片描述
svg组件

<template>
  <svg :icon-class="svgClass" aria-hidden="true">
    <use :xlink:href="iconName" />
  </svg>
</template>

<script>

export default {
	  name: 'SvgIcon',
	  props: {
	    iconClass: {
	      // type: String,
	      required: true
	    },
	    className: {
	      type: String,
	      default: ''
	    }
	  },
  computed: {
    iconName() {
      return `#icon-${this.iconClass}`
    },
    svgClass() {
      if (this.className) {
        return 'svg-icon ' + this.className
      } else {
        return 'svg-icon'
      }
    },
  }
}
</script>

icons文件里面存放svg图标代码 ,index.js为批量引入svg图标代码方法

  • 作者:Zero0985
  • 原文链接:https://blog.csdn.net/qq_41742961/article/details/121117393
    更新时间:2022-07-25 14:27:53