Created
May 15, 2019 12:00
-
-
Save blogscot/dd7eac5a532d4d8792ad76d653a3a432 to your computer and use it in GitHub Desktop.
An example of how to use Vue Slot Props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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