Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use-request auto collect deps first request twice #140

Merged
merged 2 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/hooks/src/useRequest/docs/refreshDeps/demo/demo1.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<vhp-button type="button" @click="count++">count is {{ count }}</vhp-button>
<div style="opacity: 0.6;"> count !==0 and count !==5 ready is true </div>
</div>
<br>
<br />
<vhp-button @click="() => (id = 1)">Change ID = 1</vhp-button>
<vhp-button @click="() => (id = 2)" style="margin-left: 16px;">Change ID = 2</vhp-button>
<vhp-button @click="() => (store.id = 1)" style="margin-left: 16px;">
Expand Down Expand Up @@ -77,7 +77,7 @@
})
const count = ref(0)

const ready = computed(() => count.value !== undefined)
const ready = computed(() => count.value !== 0 && count.value !== 5)
const { data, loading } = useRequest(
() => getUsername({ id: id.value, storeId: store.id, count: count.value }),
{
Expand All @@ -89,7 +89,6 @@
},
ready,
refreshDeps: true,
debounceWait: 1000,
},
)
</script>
2 changes: 1 addition & 1 deletion packages/hooks/src/useRequest/plugins/useAutoRunPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const useAutoRunPlugin: UseRequestPlugin<unknown, unknown[]> = (
const hasAutoRun = ref(false)

watchEffect(() => {
if (!manual) hasAutoRun.value = unref(ready)
if (!manual && fetchInstance.options.refreshDeps !== true) hasAutoRun.value = unref(ready)
})

if (refreshDeps instanceof Array)
Expand Down