useFetch query params #1637
-
Is there any way to pass reactive query parameters for GET request? Or using |
Beta Was this translation helpful? Give feedback.
Answered by
curtgrimes
Aug 9, 2022
Replies: 1 comment 4 replies
-
I think using a Demo: https://stackblitz.com/edit/vue3-script-setup-with-vite-ppshjm?file=src%2FApp.vue <script setup lang="ts">
import { ref, computed } from 'vue';
import { useFetch, useUrlSearchParams } from '@vueuse/core';
const foo = ref('12345');
const url = computed(() => {
const _url = new URL('https://httpbin.org/get');
_url.search = new URLSearchParams({
foo: foo.value,
});
return _url.toString();
});
const { data, isFetching } = useFetch(url, { refetch: true });
</script>
<template>
<label>Change value: <input type="text" v-model="foo" autofocus /></label>
<p>
<strong>URL:</strong> <a :href="url" target="_blank">{{ url }}</a>
</p>
<p><strong>Data:</strong> {{ isFetching ? 'Loading...' : data }}</p>
</template> |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
extrem7
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think using a
computed
like this is probably one good way to pass reactive query parameters in for a GET request. In this demo you can change the input value and see that new URL gets fetched immediately:Demo: https://stackblitz.com/edit/vue3-script-setup-with-vite-ppshjm?file=src%2FApp.vue