0

I'm still quite new to the world of Vue so I've been struggling a little with the task I have in hands.

Let me explain what should it be doing:
So we have a JSON structure that comes from our API, and the idea is to create a dynamic "Content Component" that will fetch data from the JSON and will say to the component how it is going to be build up the layout.

I've created dynamic component that loads correctly the structure that comes from the API, that looks like the image bellow:

Content diagram

So imagine that we have 2 sections, one with a simple form (left section in photo) and other section with, lets say a "List Component", see code:

This is my "Content Component":

 <template>
    <main class="dynamic-component" v-if="structure.view">
        <ContentHeader v-if="structure.view.actions" :actions="structure.view.actions"></ContentHeader>
        <ContentBody :structure="structure" :key="componentKey" :componentKey="componentKey" @force-render="forceRerender"></ContentBody>
    </main>
</template>

The "ContentBody" is here I parse the structure that comes from JSON, and this part is where I create the section with the "List Component":

<template v-if="section.url" v-slot:card-body>
  <Content :key="componentKey" :targetPath="section.url">
  </Content>
</template>

Its calling the parent component (Content) again, because Content is the dynamic component like I said before and the targetPath is to fetch data from JSON, this is returning the data to build a "List Component".

Like this: layout

My problem is when that List/Form component has actions(view, edit...) to be triggered, how can I trigger them "inside" the component and render only the SECTION and not all the page?

1 Answer 1

1

I didn't quite understand your question, but I think you'll need: Dynamic component https://v2.vuejs.org/v2/guide/components-dynamic-async.html

Or simple call component with condition v-if with a computed

Sign up to request clarification or add additional context in comments.

5 Comments

If you use vuejs 3 you can use Suspense vueschool.io/articles/vuejs-tutorials/…
Thanks for the reply @Mysterdev, yeah I tried not to be that confusing sorry.
But the idea was to have like an recursive component, like: Content (1) --Content (2) ----Content (3) ------Content (4) ... and so on. And imagine that you trigger an action inside Content (3) that you want to fetch new structure from API, you should only be rendering the new data inside Content (3) and don't change the parents above. Not sure if It was more clear or not. And thanks for the that article about Suspense I didn't know about it !! :)
if I understood correctly you want only one of the components to be updated but not the others if that's right, look at v-memo vuejs.org/api/built-in-directives.html#v-memo
Oh sorry, I thought I have replied to the comment. Thanks Mysterdev that solved my issue!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.