|
1 | 1 | <template>
|
2 | 2 | <div style="margin-top: 16px;">
|
3 | 3 | <div>
|
4 |
| - <p>id:{{ id }}</p> |
5 |
| - <p>storeID:{{ store.id }}</p> |
| 4 | + <vhp-button type="button" @click="count++">count is {{ count }}</vhp-button> |
| 5 | + <div style="opacity: 0.6;"> count !==0 and count !==5 ready is true </div> |
6 | 6 | </div>
|
| 7 | + <br> |
7 | 8 | <vhp-button @click="() => (id = 1)">Change ID = 1</vhp-button>
|
8 | 9 | <vhp-button @click="() => (id = 2)" style="margin-left: 16px;">Change ID = 2</vhp-button>
|
9 | 10 | <vhp-button @click="() => (store.id = 1)" style="margin-left: 16px;">
|
|
14 | 15 | </vhp-button>
|
15 | 16 | </div>
|
16 | 17 | <div style="margin-top: 16px;">Loading:{{ loading ? 'loading' : '' }}</div>
|
| 18 | + |
17 | 19 | <div style="margin-top: 16px;"
|
18 |
| - >Data Value: <span>{{ data }}</span> |
| 20 | + >Data Value: |
| 21 | + <div> |
| 22 | + <table> |
| 23 | + <thead> |
| 24 | + <th>Time</th> |
| 25 | + <th>Id</th> |
| 26 | + <th>StoreId</th> |
| 27 | + <th>Count</th> |
| 28 | + </thead> |
| 29 | + <tbody> |
| 30 | + <tr> |
| 31 | + <th>{{ data?.time }}</th> |
| 32 | + <th>{{ data?.id }}</th> |
| 33 | + <th>{{ data?.storeId }}</th> |
| 34 | + <th>{{ data?.count }}</th> |
| 35 | + </tr> |
| 36 | + </tbody> |
| 37 | + </table> |
| 38 | + </div> |
19 | 39 | </div>
|
20 | 40 | </template>
|
21 | 41 |
|
22 | 42 | <script lang="ts" setup>
|
23 |
| - import { ref, reactive } from 'vue' |
| 43 | + import { ref, reactive, computed } from 'vue' |
24 | 44 |
|
25 | 45 | import { useRequest } from 'vue-hooks-plus'
|
26 | 46 |
|
27 |
| - function getUsername({ id, storeId }: { id: number; storeId: number }): Promise<string> { |
| 47 | + function getUsername({ |
| 48 | + id, |
| 49 | + storeId, |
| 50 | + count, |
| 51 | + }: { |
| 52 | + id: number |
| 53 | + storeId: number |
| 54 | + count: number |
| 55 | + }): Promise<{ |
| 56 | + time: number | string |
| 57 | + id: number | string |
| 58 | + storeId: number | string |
| 59 | + count: number | string |
| 60 | + }> { |
28 | 61 | return new Promise(resolve => {
|
29 | 62 | setTimeout(() => {
|
30 |
| - resolve(`${String(Date.now())}; \n Params id: ${id} \t; Params storeId: ${storeId}`) |
| 63 | + resolve({ |
| 64 | + time: Date.now(), |
| 65 | + id, |
| 66 | + storeId, |
| 67 | + count, |
| 68 | + }) |
31 | 69 | }, 1000)
|
32 | 70 | })
|
33 | 71 | }
|
34 | 72 | const id = ref(1)
|
35 | 73 | const store = reactive({
|
36 | 74 | id: 1,
|
37 | 75 | })
|
38 |
| - const { data, loading } = useRequest(() => getUsername({ id: id.value, storeId: store.id }), { |
39 |
| - refreshDeps: [id, () => store.id], |
40 |
| - }) |
| 76 | + const count = ref(0) |
| 77 | + const ready = computed(() => count.value !== 0 && count.value !== 5) |
| 78 | + const { data, loading } = useRequest( |
| 79 | + () => getUsername({ id: id.value, storeId: store.id, count: count.value }), |
| 80 | + { |
| 81 | + initialData: { |
| 82 | + time: Date.now(), |
| 83 | + id: '-', |
| 84 | + count: '-', |
| 85 | + storeId: '-', |
| 86 | + }, |
| 87 | + ready, |
| 88 | + refreshDeps: [id, () => store.id, count], |
| 89 | + }, |
| 90 | + ) |
41 | 91 | </script>
|
0 commit comments