Skip to content

Commit 6cdb1dc

Browse files
committed
Update Async.vue
1 parent 76d5169 commit 6cdb1dc

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

playgrounds/vue3/resources/js/Pages/Async.vue

+22-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default { layout: Layout }
55

66
<script setup lang="ts">
77
import { Head, router, useForm } from '@inertiajs/vue3'
8-
import { onMounted, onUnmounted, ref, watch } from 'vue'
8+
import { ref, watch } from 'vue'
99
1010
let timer = null
1111
const reloadCount = ref(0)
@@ -61,20 +61,25 @@ const triggerLongReload = () => {
6161
})
6262
}
6363
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')
6771
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+
}
7580
76-
onUnmounted(() => {
77-
clearInterval(timer)
81+
watch(reloadCount, () => {
82+
console.log('watched reload count value', reloadCount.value)
7883
})
7984
</script>
8085

@@ -116,5 +121,9 @@ onUnmounted(() => {
116121
<p>Simply trigger a 4 second reload so you can navigate or do whatever you'd like during it.</p>
117122
<button @click="triggerLongReload" class="px-4 py-2 text-white bg-green-600 rounded">Trigger Long Reload</button>
118123
</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>
119128
</div>
120129
</template>

0 commit comments

Comments
 (0)