-
In the last few examples here you're neither specifying a Going off of the earlier examples this is what I came up with: export const useDeck = defineQuery(() => {
const deckId = Number(useRoute("decks-deckId").params.deckId);
const result = useQuery({
key: () => ["decks", { deckId }],
query: () => useRequestFetch()(`/api/decks?deckId=${deckId}`).then(decks => {
return decks.find(d => d.id === deckId);
}) as Promise<(Deck & { cardCount: number }) | undefined>,
});
return {
...result,
deckId,
}
}); But I'm not getting it to retrigger as the Edit: Ok so switching to export const useDeck = defineQuery(() => {
const deckId = useRouteParams("deckId", '-1', { transform: Number });
const result = useQuery({
key: () => ["decks", { deckId: deckId.value }],
query: () => useRequestFetch()(`/api/decks?deckId=${deckId.value}`).then(decks => {
return decks.find(d => d.id === deckId.value);
}) as Promise<(Deck & { cardCount: number }) | undefined>,
});
return {
...result,
deckId,
}
}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You don't need export const useDeck = defineQuery(() => {
const deckId = useRoute("decks-deckId");
const result = useQuery({
key: () => ["decks", { deckId: Number(route.params.deckId) }],
query: () => useRequestFetch()(`/api/decks?deckId=${deckId}`).then(decks => {
return decks.find(d => d.id === deckId);
}) as Promise<(Deck & { cardCount: number }) | undefined>,
});
return {
...result,
deckId,
}
}); You can find more about the reactive limitation in Vue docs: https://vuejs.org/guide/essentials/reactivity-fundamentals.html#limitations-of-reactive |
Beta Was this translation helpful? Give feedback.
You don't need
useRouteParams()
but you need to adaptkey
so thatdeckId
is a reactive value instead of a plain one. In the first example you need to passroute.params.deckId
.route
is reactive butdeckId
is just a string primitive once readYou can find more about the re…