Iconfont在Vue中的使用

开始

首先在iconfont图标库中找到自己喜欢的图标加入到项目中

Symbol图标(彩色)

封装成组件使用

创建以下文件 :

**iconfont.js文件**
将浏览器iconfont在线地址打开后 粘贴到iconfont.js中
**BaseSvgIcon/index.vue**
<template>
  <svg :class="iconClass" aria-hidden="true" v-on="$listeners">
    <use :xlink:href="Name" />
  </svg>
</template>

<script>
export default {
  name: "SvgIcon",
  props: {
    iconName: {
      type: String,
      required: true
    },
    iconClass: {
      type: String,
      default: "icon svg-icon"
    }
  },
  computed: {
    Name() {
      return `#icon-${this.iconName}`;
    }
  }
};
</script>

<style scoped>
.svg-icon {
  width: 60px;
  height: 60px;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}
.svg-external-icon {
  background-color: currentColor;
  mask-size: cover !important;
  display: inline-block;
}
</style>

使用

<template>
  <div id="asdad" style="display:flex">
    <SvgIcon iconName="shuxue" />
  </div>
</template>

效果

posted @ 2019-08-26 21:36  仲吕  阅读(707)  评论(0编辑  收藏  举报