Skip to content

Commit

Permalink
chore: fix watch param
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlubos committed Jan 12, 2025
1 parent 7e4b6d8 commit b734e8f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
14 changes: 11 additions & 3 deletions examples/openapi-ts-nuxt/components/home.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<script setup lang="ts">
import { getPetById } from '~/client';
const petId = ref(BigInt(8));
function incrementPetId() {
petId.value++;
}
/**
* useAsyncData
*
Expand All @@ -11,11 +17,13 @@ import { getPetById } from '~/client';
* Result: { cookies: {} }
*/
const asyncData = await getPetById({
asyncDataOptions: {},
asyncDataOptions: {
watch: [petId],
},
composable: 'useAsyncData',
key: 'item',
path: {
petId: BigInt(8),
petId,
},
});
Expand Down Expand Up @@ -88,7 +96,6 @@ watch(lazyFetch.data, (newPet) => {
});
async function handleFetch() {
const petId = ref(BigInt(8));
const result = await getPetById({
composable: '$fetch',
path: {
Expand All @@ -103,5 +110,6 @@ async function handleFetch() {
<h1>Get Random Pet Nuxt APIs</h1>
<div>
<button @click="handleFetch" type="button">$fetch</button>
<button @click="incrementPetId" type="button">increment petId</button>
</div>
</template>
10 changes: 6 additions & 4 deletions packages/client-nuxt/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ export const createClient = (config: Config = {}): Client => {
opts.headers.delete('Content-Type');
}

const url = buildUrl(opts);

const fetchFn = opts.$fetch;

if (composable === '$fetch') {
Expand All @@ -100,16 +98,20 @@ export const createClient = (config: Config = {}): Client => {
}

if (composable === 'useFetch') {
const url = buildUrl(opts);
return useFetch(url, opts);
}

if (composable === 'useLazyFetch') {
const url = buildUrl(opts);
return useLazyFetch(url, opts);
}

const handler: (ctx?: NuxtApp) => Promise<any> = () =>
const handler: (ctx?: NuxtApp) => Promise<any> = () => {
const url = buildUrl(opts);
// @ts-expect-error
fetchFn(url, opts);
return fetchFn(url, opts);
};

if (composable === 'useAsyncData') {
return key
Expand Down

0 comments on commit b734e8f

Please sign in to comment.