美文网首页
纯样式的svg-icon

纯样式的svg-icon

作者: Frank_Fang | 来源:发表于2023-10-29 17:50 被阅读0次

// components/SvgIcon/index.vue

<template>
  <div class="svg-icon" :style="{maskImage: `url(${imgUrl})`, maskRepeat: 'no-repeat',  maskPosition: 'center', width,  height,  backgroundColor: color}"></div>
</template>
<script>
export default {
  props: {
    imgUrl: {
      type: String,
      default: ''
    },
    width: {
      type: String,
      default: '20px'
    },
    height: {
      type: String,
      default: '20px'
    },
    color: {
      type: String,
      default: '#000'
    }
  }
}
</script>

<style scoped>
.svg-icon {
  display: block;
  width: 42px;
  height: 40px;
  background-color: #252525;
  cursor: pointer;
}
</style>

全局注册
// main.js

import SvgIcon from '@/components/SvgIcon'
Vue.component('svg-icon', SvgIcon)

使用

<svg-icon :imgUrl="require('@/assets/images/svg/'+item.icon+'.svg')" width="40px" height="40px" color="#666"></svg-icon>

相关文章

网友评论

      本文标题:纯样式的svg-icon

      本文链接:https://www.haomeiwen.com/subject/akuvidtx.html