Skip to content

Commit 73babc4

Browse files
committed
feat[SvgIcon]: support import svg from url (#2052)
1 parent cc7554f commit 73babc4

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/components/SvgIcon/index.vue

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
<template>
2-
<svg :class="svgClass" aria-hidden="true" v-on="$listeners">
2+
<div v-if="isExternal" :style="styleExternalIcon" class="svg-external-icon svg-icon" v-on="$listeners" />
3+
<svg v-else :class="svgClass" aria-hidden="true" v-on="$listeners">
34
<use :xlink:href="iconName" />
45
</svg>
56
</template>
67

78
<script>
9+
// doc: https://panjiachen.github.io/vue-element-admin-site/feature/component/svg-icon.html#usage
10+
import { isExternal } from '@/utils/validate'
11+
812
export default {
913
name: 'SvgIcon',
1014
props: {
@@ -18,6 +22,9 @@ export default {
1822
}
1923
},
2024
computed: {
25+
isExternal() {
26+
return isExternal(this.iconClass)
27+
},
2128
iconName() {
2229
return `#icon-${this.iconClass}`
2330
},
@@ -27,6 +34,12 @@ export default {
2734
} else {
2835
return 'svg-icon'
2936
}
37+
},
38+
styleExternalIcon() {
39+
return {
40+
mask: `url(${this.iconClass}) no-repeat 50% 50%`,
41+
'-webkit-mask': `url(${this.iconClass}) no-repeat 50% 50%`
42+
}
3043
}
3144
}
3245
}
@@ -40,4 +53,10 @@ export default {
4053
fill: currentColor;
4154
overflow: hidden;
4255
}
56+
57+
.svg-external-icon {
58+
background-color: currentColor;
59+
mask-size: cover!important;
60+
display: inline-block;
61+
}
4362
</style>

0 commit comments

Comments
 (0)