-
Notifications
You must be signed in to change notification settings - Fork 1
/
9. methods.html
61 lines (44 loc) · 1.35 KB
/
9. methods.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
<!DOCTYPE html>
<html>
<head>
<title>Methods</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">
<methods :min="10" :max="4000" inline-template>
<div class="card p-4">
<div class="alert alert-warning">
<strong>Your number:</strong> {{ number }}
</div>
<button class="btn btn-primary" @click.prevent="randomise">Random number</button>
</div>
</methods>
</div>
<script type="text/javascript">
Vue.component('methods', {
props: ['min', 'max'],
data() {
return {
number: -1
}
},
mounted() {
this.randomise()
},
methods: {
generateNumber() {
return Math.floor((Math.random() * this.max) + this.min)
},
randomise() {
this.number = this.generateNumber()
}
}
})
new Vue({
el: '#my-app'
})
</script>
</body>
</html>