-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemo1.vue
79 lines (71 loc) · 1.29 KB
/
Demo1.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<template>
<div class="demo1"></div>
</template>
<script>
import GRender, { Rect, Line, Arrow, Circle, Ellipse } from 'grender'
export default {
name: 'Demo1',
mounted() {
this.grender = new GRender(this.$el)
const x = this.$el.offsetWidth / 2 - 30
const rect = new Rect({
shape: {
x,
y: 40,
width: 80,
height: 40
}
})
const line = new Line({
shape: {
x1: x - 50,
y1: 40,
x2: x + 50,
y2: 160
}
})
const arrow = new Arrow({
shape: {
x1: x - 30,
y1: 40,
x2: x + 10,
y2: 160
}
})
const circle = new Circle({
shape: {
x,
y: 100,
r: 40
}
})
const ellipse = new Ellipse({
shape: {
x: x + 60,
y: 120,
rx: 60,
ry: 30
}
})
this.grender.add(rect)
this.grender.add(line)
this.grender.add(arrow)
this.grender.add(circle)
this.grender.add(ellipse)
window.addEventListener('resize', this.resize)
},
destroyed() {
window.removeEventListener('resize', this.resize)
this.grender.destroy()
},
methods: {
resize() {
this.grender.resize()
}
}
}
</script>
<style lang="stylus">
.demo1
height 180px
</style>