Skip to content

Instantly share code, notes, and snippets.

@blogscot
Created May 15, 2019 12:00
Show Gist options
  • Save blogscot/dd7eac5a532d4d8792ad76d653a3a432 to your computer and use it in GitHub Desktop.
Save blogscot/dd7eac5a532d4d8792ad76d653a3a432 to your computer and use it in GitHub Desktop.
An example of how to use Vue Slot Props
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>VueJS</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<div id="app"></div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<script src="index.js"></script>
</body>
</html>
const MyParent = Vue.component('my-parent', {
data: function() {
return {
parentVal: 'value of parent',
}
},
template: `
<div>
<h3>Parent's Children:</h3>
<slot :signal="parentVal"></slot>
</div>`,
})
const MyChild = Vue.component('my-child', {
props: ['signal'],
template: '<h3>Showing child {{signal}}</h3>',
})
new Vue({
el: '#app',
components: {
MyParent,
MyChild,
},
template: `
<my-parent v-slot="{signal}">
<my-child :signal="signal"></my-child>
<my-child :signal="signal"></my-child>
</my-parent>`,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment