z-svg.vue
1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<template>
<image class="z-svg" :class="classBind" :src="src" mode="aspectFit" :style="{ width: svgWidth, height: svgHeight }" @click="$emit('click')" />
</template>
<script>
export default {
name: 'ZSvg',
props: {
name: {
type: String,
required: true,
},
size: {
type: [Number, String],
default: 'inherit',
},
width: String,
height: String,
},
computed: {
classBind() {
const normalClass = '';
if (this.$options && this.$options.propsData && this.$options.propsData.className) {
return normalClass + ' ' + this.$options.propsData.className;
}
return normalClass;
},
src({ name }) {
return this.formatImagePath(name, 'svg')
},
svgWidth({ width, size }) {
if (![undefined, null, ''].includes(width)) return width;
if (typeof size === 'number') {
return `${size}px`;
} else {
return size;
}
},
svgHeight({ height, size }) {
if (![undefined, null, ''].includes(height)) return height;
if (typeof size === 'number') {
return `${size}px`;
} else {
return size;
}
},
},
}
</script>
<style lang="scss">
.z-svg {
font-size: 0;
}
</style>