File tree 6 files changed +51
-9
lines changed 6 files changed +51
-9
lines changed Original file line number Diff line number Diff line change @@ -12,10 +12,12 @@ import IconJavaScript from "./IconJavaScript.vue"
12
12
import IconSvelte from " ./IconSvelte.vue"
13
13
import IconAngular from " ./IconAngular.vue"
14
14
import IconNuxt from " ./IconNuxt.vue"
15
- import { computed , ref } from " vue"
15
+ import { computed , ref , onBeforeUnmount } from " vue" ;
16
16
import { vAutoAnimate } from " ../../../src"
17
17
import " ../../assets/prism.css"
18
18
19
+ const timeOutID = ref ();
20
+
19
21
type LanguageOption =
20
22
| " react"
21
23
| " preact"
@@ -77,10 +79,14 @@ const copyStatus = ref(false)
77
79
function copyCode(value : string ) {
78
80
window .navigator .clipboard .writeText (value )
79
81
copyStatus .value = true
80
- setTimeout (() => {
82
+ timeOutID . value = setTimeout (() => {
81
83
copyStatus .value = false
82
84
}, 2000 )
83
85
}
86
+
87
+ onBeforeUnmount (() => {
88
+ clearTimeout (timeOutID .value );
89
+ });
84
90
</script >
85
91
86
92
<template >
Original file line number Diff line number Diff line change 1
1
<script setup lang="ts">
2
- import { ref } from " vue"
2
+ import { ref , onBeforeUnmount } from " vue" ;
3
3
import IconDown from " ./IconDown.vue"
4
4
import PoliteAd from " ./PoliteAd.vue"
5
5
import { vAutoAnimate } from " ../../../src/index"
6
6
7
+ const controller = new window .AbortController ();
8
+
7
9
const show = ref (false )
8
10
const activeTitle = ref (" Docs Navigation" )
9
11
@@ -25,8 +27,18 @@ if (typeof window !== "undefined") {
25
27
clearTimeout (resizeTimer )
26
28
window .addEventListener (" resize" , () => {
27
29
resizeTimer = setTimeout (applySizing , 200 )
30
+
31
+ this .$once (' hook:beforeUnmount' , () => {
32
+ clearTimeout (resizeTimer );
33
+ });
34
+ }, {
35
+ signal: controller ?.signal
28
36
})
29
37
}
38
+
39
+ onBeforeUnmount (() => {
40
+ controller .abort ();
41
+ });
30
42
</script >
31
43
32
44
<template >
Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ onMounted(() => {
13
13
clearInterval (interval )
14
14
}
15
15
}, duration )
16
+
17
+ this .$once (' hook:beforeUnmount' , () => {
18
+ clearInterval (interval );
19
+ });
16
20
})
17
21
</script >
18
22
Original file line number Diff line number Diff line change 1
1
<script setup>
2
- import { ref } from " vue"
2
+ import { ref , onBeforeUnmount } from " vue" ;
3
3
import { vAutoAnimate } from " ../../../../src/index"
4
4
5
+ const timeOutID = ref ();
6
+
5
7
const showForm = ref (false )
6
8
const cards = ref ([
7
9
{
@@ -20,10 +22,14 @@ const cards = ref([
20
22
21
23
function createCard (card ) {
22
24
cards .value .unshift (card)
23
- setTimeout (() => {
25
+ timeOutID . value = setTimeout (() => {
24
26
showForm .value = false
25
27
}, 300 )
26
28
}
29
+
30
+ onBeforeUnmount (() => {
31
+ clearTimeout (timeOutID .value );
32
+ });
27
33
</script >
28
34
29
35
<template >
Original file line number Diff line number Diff line change 1
1
<script setup lang="ts">
2
- import { ref } from " vue"
2
+ import { ref , onBeforeUnmount } from " vue" ;
3
3
import { useAutoAnimate } from " ../../../../src/vue"
4
4
5
+ const intervalID = ref ();
6
+
5
7
const balls = ref ([" red" , " green" , " blue" ])
6
8
const [parent, enable] = useAutoAnimate ({ duration: 500 })
7
9
@@ -10,9 +12,14 @@ function toggle() {
10
12
isEnabled .value ? enable (false ) : enable (true )
11
13
isEnabled .value = ! isEnabled .value
12
14
}
13
- setInterval (() => {
15
+
16
+ intervalID .value = setInterval (() => {
14
17
balls .value .push (balls .value .shift ()! )
15
18
}, 600 )
19
+
20
+ onBeforeUnmount (() => {
21
+ clearInterval (intervalID .value );
22
+ });
16
23
</script >
17
24
18
25
<template >
Original file line number Diff line number Diff line change 1
1
<script setup>
2
- import { ref } from " vue"
2
+ import { ref , onBeforeUnmount } from " vue" ;
3
3
import { useAutoAnimate } from " ../../../../src/vue"
4
4
5
+ const intervalID = ref ();
6
+
5
7
const balls = ref ([" red" , " green" , " blue" ])
6
8
const [parent , enable ] = useAutoAnimate ({ duration: 500 })
7
9
@@ -10,9 +12,14 @@ function toggle() {
10
12
isEnabled .value ? enable (false ) : enable (true )
11
13
isEnabled .value = ! isEnabled .value
12
14
}
13
- setInterval (() => {
15
+
16
+ intervalID .value = setInterval (() => {
14
17
balls .value .push (balls .value .shift ()! )
15
18
}, 600 )
19
+
20
+ onBeforeUnmount (() => {
21
+ clearInterval (intervalID .value );
22
+ });
16
23
</script >
17
24
18
25
<template >
You can’t perform that action at this time.
0 commit comments