2022年下半年的面:
// 这里的 xlink: href ="#阿里图标复制的类名" 。点击项目的 Symbol 标签,复制代码。<svg aria-hidden="true"> <use xlink:href="#icon-xxx"></use></svg>
遇到不能修改颜色的彩色图标时,参考:svg图标无法修改颜色的解决方案
项目应用组件使用:
<svg-icon icon- />
组件注册:
import Vue from 'vue'import SvgIcon from '@/components/SvgIcon'// svg component// register globallyVue.component('svg-icon', SvgIcon)
组件编写:
<template> // 无法找到相应图标时设置默认显示 <div v-if="isExternal" :style="styleExternalIcon" v-on="$$listeners" > </div> <svg v-else : aria-hidden="true" v-on="$$listeners"> <use :xlink:href="iconName" /> </svg></template><script>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: 2em; height: 1em; /* vertical-align: -0.15em; */ fill: currentColor; overflow: hidden; color: #B0B6C6; /* height: 20px; */}.svg-external-icon { background-color: currentColor; mask-size: cover!important; display: inline-block;}</style>
/utils/validate 文件
export function isExternal(path) { return /^(https?:|mailto:|tel:)/.test(path)}
font-class 引用font-class是unicode使用方式的一种变种,主要是解决unicode书写不直观,语意不明确的问题。
与unicode使用方式相比,具有如下特点:
<i ></i>
姓名:
年龄:
电话: