File tree 1 file changed +38
-38
lines changed
1 file changed +38
-38
lines changed Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments