Skip to content

Instantly share code, notes, and snippets.

@ErikCH
Created February 8, 2019 05:24
Show Gist options
  • Select an option

  • Save ErikCH/e9883d1fe70cdfda1e5a9e1adbcd1a9a to your computer and use it in GitHub Desktop.

Select an option

Save ErikCH/e9883d1fe70cdfda1e5a9e1adbcd1a9a to your computer and use it in GitHub Desktop.
Vue 2.6 slots tutorial
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>My Test App</title>
<script src="https://unpkg.com/vue"></script>
</head>
<body>
<div id="app">
{{hello}}
<comp-a>
<template v-slot:[slot] >This is the header</template>
<!-- <template v-slot:footer="{ nameInfo }" >This is the footer {{nameInfo.lastName}}</template> -->
</comp-a>
</div>
<script>
const ComponentA = {
data() {
return {
name: {firstName: 'Erik', lastName: 'Hanchett'}
}
},
template: `
<div>
<header>
<h1>Header</h1>
<slot name="header"></slot>
</header>
<footer>
<h1>Footer</h1>
<slot name="footer" :nameInfo="name"></slot>
</footer>
</div>
`
}
new Vue({
el:'#app',
data(){
return {
hello: 'Hello World',
slot: 'header'
}
},
components: {
'comp-a':ComponentA
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment