NuxtN
Nuxtβ€’15mo agoβ€’
28 replies
o.m

How do I get the updated data and display correctly?

In my frontend I have a v-for loop that loops how many cards are there
Curriculumvit.vue
<Cards
  v-for="(template, index) in templates"
  :key="index"
  :name="template.name"
  @delete="handleDeleteTemplate(template.id)"
  @edit="handleEditTemplate(template.id)"
  @preview="handlePreviewTemplate(template.id)"
  @statistics="handleStatisticsTemplate(template.id)"
/>

const handleUserTemplates = async () => {
    templates.value = await getUserTemplate();
};
-----------------------------------
// composable template.ts
const getUserTemplate = async (): Promise<any> => {
    try {
        const { data } = await useAsyncData(() =>
            requestFetch("/api/template/user", { method: "GET" })
        );
        return data.value?.body?.templates;
    } catch (err) {
        console.log(err);
    }
};

Upon first loading the page I have 2 cards but right after creating a new template I still get 2 cards even though I was able to retrieve 3 templates after the api call when i look at the network
// this is the function that calls createTemplate
const handleCreateTemplateUser = async () => {
    const { user } = useAuth();
    await createUserTemplate({
        name: name.value,
        email: user.value?.email,
    });
    closeModal();
    await refreshNuxtData();
};
Was this page helpful?