Multiple Vue components inside Main component

user616

What is the correct way to dynamically insert any number of sub components inside the main 'wrapper' component?

Something like this:

Main Parent component:

<template>
  <div id="app">
    <GridContainer v-for="item in items">
        <GridItem />
    </GridContainer>
  </div>
</template>

<script>
import { GridContainer, GridItem } from 'Grid';

export default {
  name: 'app',
  components: {
    GridContainer,
    GridItem
  },
  data() {
    return {
        items: [...array if items that are dynamic]
    };
  };
}
</script>
Daniel

do v-for on the component, not the wrapper. Like this

Your IDE may also warn you that you're missing a key, easiest way to add key is to use index (but it comes with some caveats). Also, you probably want to pass the items into the component. If you have a prop called item, you'd pass it with :item="item"

<template>
  <div id="app">
    <GridContainer>
        <GridItem  v-for="(item, k) in items" :key="k" :item="item"/>
    </GridContainer>
  </div>
</template>

<script>
import { GridContainer, GridItem } from 'Grid';

export default {
  name: 'app',
  components: {
    GridContainer,
    GridItem
  },
  data() {
    return {
        items: [...array if items that are dynamic]
    };
  };
}
</script>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Vue: components inside component

Append components inside other component in Vue JS

React | Gatsby: Components inside or outside main page component

Strange Activity From Using Two Vue Components inside another Component

How to create multiple Vue components inside of Bootstrap tabs?

Vue components inside cycle

Main component not showing other components

Adding child Vue components inside of Vue components

Vue on click inside component

Multiple modal components with Vue

Vue.js dynamic components - load only when data is fetched inside component

Vue 2 - using components inside components

Angular 2, component inside main component

How to embed one React-Admin component inside another; multiple Admin components

Running multiple Components in one component

React - Component export multiple components

Passing Components as children through a main Form component

Using Vue, what is the best way to use a Pagination component in multiple parent components?

How to import a js class in main.js file of a vue.js project and use it in all the components instead of importing in each component?

Adding a content inside of a vue component

Using vue mixin inside @Component

Vue - detect component inside slot

Cakephp components inside another component performance

Spreading props on a component and destructuring inside a components with typescript

ReactJS: access components inside component "parent"

How to add same component inside components

How to add components conditionally inside another component

Component Parts inside of Components with Enterprise Architect

How to use "for/in" to find components inside of another component?