-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSvgColored.vue
42 lines (38 loc) · 1.04 KB
/
SvgColored.vue
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
<template>
<svg-image :src="svgWithColor" />
</template>
<script>
import { fromData } from '@sergeymell/nativescript-svg'
export default {
props: {
color: {
type: [String, Array],
default: null,
},
replaceColor: {
type: [String, Array],
default: null,
},
src: {
type: String,
required: true,
},
},
computed: {
svgWithColor() {
let svg = this.src
if (this.color && this.replaceColor) {
if (Array.isArray(this.replaceColor)) {
this.replaceColor.forEach((replaceColor, index) => {
const color = this.color[index] || this.color[0]
svg = svg.replace(new RegExp(replaceColor, 'g'), color)
})
} else {
svg = svg.replace(new RegExp(this.replaceColor, 'g'), this.color)
}
}
return fromData(svg)
},
},
}
</script>