This repository has been archived by the owner on Jul 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (55 loc) · 1.42 KB
/
index.js
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
export default {
install (Vue, options) {
Vue.component('v-svg', {
render (h) {
return h('svg', {
attrs: {
width: this.width,
height: this.height,
viewBox: this.viewBox,
className: options.className || ''
},
style: {
display: 'inline-block',
strokeWidth: 0,
stroke: 'currentColor',
fill: 'currentColor',
overflow: 'hidden'
}
}, [ h('use', { attrs: { 'xlink:href': `${this.filepath}#${this.prefix}${this.sprite}` } }) ])
},
data () {
return {
width: null,
height: null,
viewBox: null,
}
},
props: {
filepath: {
type: String,
default: options.filepath || ''
},
prefix: {
type: String,
default: options.prefix || ''
},
sprite: {
type: String,
default: options.sprite || ''
},
size: {
type: String,
default: options.size || '32'
}
},
created () {
let sizes = this.size.split(/[ ,|]+/)
let length = sizes.length
this.width = length < 4 ? sizes[0] : sizes[2]
this.height = length < 4 ? sizes[--length] : sizes[3]
this.viewBox = length < 4 ? `0 0 ${this.width} ${this.height}` : sizes.join(' ')
}
})
}
}