A
A
Artem2019-07-29 17:41:36
Vue.js
Artem, 2019-07-29 17:41:36

Is it possible in a Vue component to connect any component from the parent?

Is it possible in a Vue component to connect any component from the parent?
In the App component, I create component A and pass some data there via props, and among this data, the names of the components can be transferred. Inside A, I include these components like this:
div v-if="el.componentName" :is="el.componentName"
But for this to work, I have to import the components in A and include them in components. As a result, the question arose, is it possible to connect components in A somehow from the parent App, so that in A they are eventually connected dynamically?
Code: https://codesandbox.io/s/vue-template-ks07w

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FullStack Alex, 2019-07-30
@erlinvig

Instead of a component name, just pass the component itself. Accordingly, the component must be imported into the parent App. In my applications, I pass components through Vuex, but with props I think it should also work.
Only instead of components it will be necessary to declare a dynamic component in data. Here is a simple example:
https://codesandbox.io/s/vue-template-ifw07

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question