最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

一文帶你搞定svg-icon的使用方式

 更新時(shí)間:2023年05月24日 11:44:01   作者:小白在線學(xué)前端  
這篇文章主要介紹了一文帶你搞定svg-icon的使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

svg-icon的使用方式

前置

有的時(shí)候,我們經(jīng)常在業(yè)務(wù)中會(huì)需要使用字體圖標(biāo)的場(chǎng)景,比如同一個(gè)圖標(biāo)在不同的地方顯示不同的顏色,這個(gè)時(shí)候我們使用字體圖標(biāo)就非常的合適,

這篇文章我們主要講的是在Vue中顯示的字體圖標(biāo)`svg-icon`的使用 # 開始啦!

第一步:下載相應(yīng)的**包**或者**插件**(會(huì)提示沒有安裝xml-loader,只需要安裝下xml-loader,重啟下項(xiàng)目就可以解決報(bào)錯(cuò))

## 使用npm
npm install vue-svg-icon xml-loader -D
## 使用yarn 
yarn add vue-svg-icon xml-loader 

第二步:把從iconfont下載的.svg的文件

第三步:在icon的Vue組件中寫代碼 ../src/components/svgIcon/index.vue

<template>
  <div v-if="isExternal" :style="styleExternalIcon" class="svg-external-icon svg-icon" v-on="$listeners" />
  <svg v-else :class="svgClass" aria-hidden="true" v-on="$listeners">
    <use :xlink:href="iconName" rel="external nofollow"  />
  </svg>
</template>
<script>
// doc: https://panjiachen.github.io/vue-element-admin-site/feature/component/svg-icon.html#usage
import { isExternal } from '@/utils/validate'
export default {
  name: 'SvgIcon',
  props: {
    iconClass: {
      type: String,
      required: true
    },
    className: {
      type: String,
      default: ''
    }
  },
  computed: {
    isExternal() {
      return isExternal(this.iconClass)
    },
    iconName() {
      return `#icon-${this.iconClass}`
    },
    svgClass() {
      if (this.className) {
        return 'svg-icon ' + this.className
      } else {
        return 'svg-icon'
      }
    },
    styleExternalIcon() {
      return {
        mask: `url(${this.iconClass}) no-repeat 50% 50%`,
        '-webkit-mask': `url(${this.iconClass}) no-repeat 50% 50%`
      }
    }
  }
}
</script>
<style scoped>
.svg-icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}
.svg-external-icon {
  background-color: currentColor;
  mask-size: cover!important;
  display: inline-block;
}
</style>

第四步:在存放svg的文件夾外部,創(chuàng)建一個(gè)index.js文件

如下

代碼如下:

import Vue from 'vue'
import SvgIcon from '@/components/SvgIcon'// svg component
// register globally
Vue.component('svg-icon', SvgIcon)
// 在./svg下查找 “.svg”文件
const req = require.context('./svg', false, /\.svg$/)
const requireAll = requireContext => requireContext.keys().map(requireContext)
requireAll(req)

第四步:在main.js中引入icon/index.js文件中全局設(shè)置

//全局加載就可以了
import '@/icons/index.js'

第五步:直接在Vue組件中使用即可,直接使用文件名就可以了。

<div>
  <svg-icon icon-class="language" />
</div>

效果圖

注意:

svg-icon是前端經(jīng)常使用的,必須要會(huì)使用。

icon圖標(biāo)在線生成教程(svg轉(zhuǎn)icon)

1、準(zhǔn)備好項(xiàng)目的Svg文件

2、訪問(wèn)在線生成工具,網(wǎng)址:https://icomoon.io

3、其余操作步驟按照如下截圖

(1)點(diǎn)擊右上角“icoMoon App”按鈕

 (2)點(diǎn)擊按鈕導(dǎo)入svg文件

(3)查看使用方法 

(4)定義下載文件名稱和相關(guān)配置

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

巴南区| 柳河县| 临泉县| 珲春市| 女性| 上饶县| 宜兰县| 凤山市| 青阳县| 嘉禾县| 宁强县| 馆陶县| 襄城县| 岳池县| 育儿| 石嘴山市| 阿拉善左旗| 金塔县| 连江县| 康保县| 凤山县| 马尔康县| 高雄市| 行唐县| 渭南市| 确山县| 印江| 元江| 江城| 邵阳县| 措勤县| 宝应县| 班戈县| 黄冈市| 托里县| 宁海县| 保靖县| 格尔木市| 安义县| 青铜峡市| 五莲县|