Skip to content

Instantly share code, notes, and snippets.

@KenoLeon
Created June 17, 2020 02:02
Show Gist options
  • Select an option

  • Save KenoLeon/c7330309d0dbeb56ed0524e999296657 to your computer and use it in GitHub Desktop.

Select an option

Save KenoLeon/c7330309d0dbeb56ed0524e999296657 to your computer and use it in GitHub Desktop.
Parent and multiple child props in Vue
<!-- FILE: App.vue -->
<!-- NOTE: Import bootstrap on main.js -->
<template>
<div id="app">
<bootsAlert v-bind="{ alertD: alertData }"/>
<bootsList v-bind="{ listD : listData }"/>
</div>
</template>
<script>
import bootsAlert from './components/bootsAlert.vue'
import bootsList from './components/bootsList.vue'
export default {
name: 'App',
components: {
bootsAlert,
bootsList
},
data() {
return {
alertData: 'This was a triumph',
listData: [
{ item: 'Eeny' },
{ item: 'Meeny' },
{ item: 'Miny' },
{ item: 'Moe' }
]
}
}
}
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
<!-- FILE: components/bootsAlert.vue -->
<template>
<div>
<div class="alert alert-success" role="alert" style="margin:auto;width:600px;">
{{alertD}}
</div>
<br>
</div>
</template>
<script>
export default {
props: ['alertD'],
name: 'bootsAlert'
}
</script>
<!-- FILE: components/bootsList.vue -->
<template>
<div>
<ul class="list-group" style="margin:auto;width:600px;">
<li v-for="element in listD" :key="element" class="list-group-item">
{{ element.item }}
</li>
</ul>
</div>
</template>
<script>
export default {
props: ['listD'],
name: 'bootsList'
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment