Skip to content

Commit be034f3

Browse files
committed
Rename lifecycle method
1 parent 2af8154 commit be034f3

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed
Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
<template>
2-
<div>
3-
<span data-testid="elapsed">{{ lapse }}ms</span>
4-
<button @click="handleRunClick">
5-
{{ running ? 'Stop' : 'Start' }}
6-
</button>
7-
</div>
8-
</template>
9-
10-
<script>
11-
export default {
12-
data() {
13-
return {
14-
running: false,
15-
lapse: 0,
16-
timer: null
17-
}
18-
},
19-
beforeDestroy() {
20-
clearInterval(this.timer)
21-
},
22-
methods: {
23-
handleRunClick() {
24-
if (this.running) {
25-
clearInterval(this.timer)
26-
} else {
27-
const startTime = Date.now() - this.lapse
28-
29-
this.timer = setInterval(() => {
30-
this.lapse = Date.now() - startTime
31-
})
32-
}
33-
34-
this.running = !this.running
35-
}
36-
}
37-
}
38-
</script>
1+
<template>
2+
<div>
3+
<span data-testid="elapsed">{{ lapse }}ms</span>
4+
<button @click="handleRunClick">
5+
{{ running ? 'Stop' : 'Start' }}
6+
</button>
7+
</div>
8+
</template>
9+
10+
<script>
11+
export default {
12+
data() {
13+
return {
14+
running: false,
15+
lapse: 0,
16+
timer: null,
17+
}
18+
},
19+
beforeUnmount() {
20+
clearInterval(this.timer)
21+
},
22+
methods: {
23+
handleRunClick() {
24+
if (this.running) {
25+
clearInterval(this.timer)
26+
} else {
27+
const startTime = Date.now() - this.lapse
28+
29+
this.timer = setInterval(() => {
30+
this.lapse = Date.now() - startTime
31+
})
32+
}
33+
34+
this.running = !this.running
35+
},
36+
},
37+
}
38+
</script>

0 commit comments

Comments
 (0)