-
Notifications
You must be signed in to change notification settings - Fork 1
/
12. extending with mixins.html
99 lines (63 loc) · 1.73 KB
/
12. extending with mixins.html
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE html>
<html>
<head>
<title>Mixins</title>
<script type="text/javascript" src="https://vuejs.org/js/vue.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
</head>
<body>
<div id="my-app" class="container pt-4 d-flex flex-row">
<mage inline-template>
<div class="card p-4 alert-info mr-4" style="min-width: 400px;">
<h2>Mage</h2>
Life: {{ hp }}<br>
Defence: {{ defence }}<br>
Attack: {{ attk }}<br>
Special: {{ fireBall() }}
</div>
</mage>
<warrior inline-template>
<div class="card p-4 alert-danger" style="min-width: 400px;">
<h2>Warrior</h2>
Life: {{ hp }}<br>
Defence: {{ defence }}<br>
Attack: {{ attk }}<br>
</div>
</warrior>
</div>
<script type="text/javascript">
const Player = {
computed: {
hp() {
return 100
},
attk() {
return 20
},
defence() {
return 20
}
}
}
Vue.component('mage', {
mixins: [Player],
methods: {
fireBall() {
return this.attk * 2
}
}
})
Vue.component('warrior', {
mixins: [Player],
computed: {
defence() {
return 50
}
}
})
new Vue({
el: '#my-app'
})
</script>
</body>
</html>