forked from pikax/vue-composable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch.html
62 lines (52 loc) · 1.19 KB
/
fetch.html
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
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
Vue.config.devtools = true
</script>
</head>
<body>
<div id="app">
<p>current Id {{id}}</p>
<p>
<button @click="id--">prev</button>
<button @click="id++">next</button>
</p>
<p v-if="loading">
loading...
</p>
<div v-else>
<p> Status: {{status}} </p>
{{ json }}
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/@vue/[email protected]/dist/vue-composition-api.umd.js"></script>
<script>
// add composition api to vue
Vue.use(vueCompositionApi.default);
</script>
<script src="../dist/vue-composable.umd.js"></script>
<script>
const {
useFetch
} = vueComposable;
const { computed, ref, watch} = vueCompositionApi;
new Vue({
el: "#app",
setup(){
const id = ref(1);
const {json , loading, exec, error, status} = useFetch();
watch(id, (id)=>{
exec('https://reqres.in/api/user/'+id);
})
return {
id,
json,
loading,
status
}
}
})
</script>
</body>
</html>