@@ -5,7 +5,7 @@ export default { layout: Layout }
5
5
6
6
<script setup lang="ts">
7
7
import { Head , router , useForm } from ' @inertiajs/vue3'
8
- import { onMounted , onUnmounted , ref , watch } from ' vue'
8
+ import { ref , watch } from ' vue'
9
9
10
10
let timer = null
11
11
const reloadCount = ref (0 )
@@ -61,20 +61,25 @@ const triggerLongReload = () => {
61
61
})
62
62
}
63
63
64
- watch (reloadCount , () => {
65
- console .log (' watched reload count value' , reloadCount .value )
66
- })
64
+ const triggerCancel = () => {
65
+ router .post (
66
+ ' /sleepy/3' ,
67
+ {},
68
+ {
69
+ onCancelToken : (token ) => {
70
+ console .log (' onCancelToken' )
67
71
68
- onMounted (() => {
69
- // timer = setTimeout(() => {
70
- // router.reload({
71
- // only: ['sleep'],
72
- // })
73
- // }, 1000)
74
- })
72
+ setTimeout (() => {
73
+ console .log (' CANCELLING!' )
74
+ token .cancel ()
75
+ }, 1000 )
76
+ },
77
+ },
78
+ )
79
+ }
75
80
76
- onUnmounted ( () => {
77
- clearInterval ( timer )
81
+ watch ( reloadCount , () => {
82
+ console . log ( ' watched reload count value ' , reloadCount . value )
78
83
})
79
84
</script >
80
85
@@ -116,5 +121,9 @@ onUnmounted(() => {
116
121
<p >Simply trigger a 4 second reload so you can navigate or do whatever you'd like during it.</p >
117
122
<button @click =" triggerLongReload" class =" px-4 py-2 text-white bg-green-600 rounded" >Trigger Long Reload</button >
118
123
</div >
124
+ <div class =" p-4 space-y-4 text-sm text-gray-500 border border-gray-300 rounded" >
125
+ <p >Trigger an automatic cancellation from the token.</p >
126
+ <button @click =" triggerCancel" class =" px-4 py-2 text-white bg-green-600 rounded" >Trigger Cancel</button >
127
+ </div >
119
128
</div >
120
129
</template >
0 commit comments