-
Notifications
You must be signed in to change notification settings - Fork 0
/
opt_drill.html
63 lines (60 loc) · 1.63 KB
/
opt_drill.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
The writing and effects shown below are the same as the official ones. <br>
以下展示的写法和效果于官方一致 <br>
<head>
<title>Vueey | tem Drill</title>
<link rel="stylesheet" href="https://unpkg.com/@tofukit/resetcss">
<!-- 解开注释,查看官方效果 | uncomment to see the official effects -->
<!-- <script src="https://unpkg.com/vue@2/dist/vue.min.js"></script> -->
<script src="https://unpkg.com/vueey@latest"></script>
</head>
<body>
<div id="app">
<button @click="count--">dec</button>
<input ref="input" :value="count" @input="count = $event.target.value">
<button @click="count++">inc</button>
<div ref="container"></div>
</div>
</body>
<script>
const app = new Vue({
el: '#app',
data: {
count: NaN,
},
methods: {
init() {
this.count = 0;
},
reached(val) {
alert(`${val} is out of range!`);
this.init();
},
},
watch: {
count(val, oldVal) {
if (Number.isNaN(val)) {
this.init();
return;
};
if (val > 3 || val < 0) this.reached(val);
this.$refs.container.innerHTML += `<p>${oldVal} --> ${val}</p>`;
},
},
created() {
console.log('(created:$refs) ' + this.$refs);
console.log('(created:count) ' + this.count);
},
mounted() {
this.init();
this.$refs.input.focus();
this.$refs.input.value = 1;
},
updated() {
console.log('(updated:count) ' + this.count);
const cont = this.$refs.container;
while (cont.childElementCount > 3) {
cont.removeChild(cont.firstChild);
}
}
});
</script>