forked from vitest-dev/vitest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.vue
73 lines (65 loc) · 1.46 KB
/
demo.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<script setup lang="ts">
import { reactive, ref } from 'vue-demi'
import { stringify } from '@vueuse/docs-utils'
import { useToggle } from '@vueuse/shared'
import { useFetch } from '.'
const url = ref('https://httpbin.org/get')
const refetch = ref(false)
const toggleRefetch = useToggle(refetch)
const {
data,
error,
abort,
statusCode,
isFetching,
isFinished,
canAbort,
execute,
} = useFetch(url, { refetch }).get()
const text = stringify(reactive({
isFinished,
isFetching,
canAbort,
statusCode,
error,
data,
}))
</script>
<template>
<div>
<div>
<note>The following URLs can be used to test different features of useFetch</note>
<div class="mt-2">
Normal Request:
<code>
https://httpbin.org/get
</code>
</div>
<div>
Abort Request:
<code>
https://httpbin.org/delay/10
</code>
</div>
<div>
Response Error:
<code>
http://httpbin.org/status/500
</code>
</div>
</div>
<input v-model="url" type="text">
<button @click="execute">
Execute
</button>
<button @click="toggleRefetch">
<carbon-checkmark v-if="refetch" />
<carbon-error v-else />
<span class="ml-2">{{ refetch ? 'Refetch On': 'Refetch Off' }}</span>
</button>
<button v-if="canAbort" class="orange" @click="abort">
Abort
</button>
<pre lang="yaml">{{ text }}</pre>
</div>
</template>