forked from mrwill84/DOClever
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsvg.vue
More file actions
executable file
·54 lines (51 loc) · 1.63 KB
/
svg.vue
File metadata and controls
executable file
·54 lines (51 loc) · 1.63 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
<template>
<object :data="src" type="image/svg+xml"/>
</template>
<style scoped>
</style>
<script>
module.exports={
props:["src","color"],
data:function () {
return {
color1:""
}
},
watch:{
color:function (val) {
var arr=this.$el.contentDocument.getElementsByTagName("path");
for(var i=0;i<arr.length;i++)
{
if(val)
{
arr[i].setAttribute("fill",val);
}
else
{
arr[i].setAttribute("fill",this.color1);
}
}
}
},
mounted:function () {
var _this=this;
this.$el.addEventListener("load", function() {
var arr=_this.$el.contentDocument.getElementsByTagName("path");
for(var i=0;i<arr.length;i++)
{
_this.color1=arr[i].getAttribute("fill");
if(_this.color)
{
arr[i].setAttribute("fill",_this.color);
}
}
var style=_this.$el.contentDocument.querySelector("style");
style.textContent+="svg { cursor: pointer; }";
var svg=_this.$el.contentDocument.querySelector("svg");
svg.addEventListener("click",function (e) {
_this.$emit("click",e);
})
});
}
}
</script>