Vue with parent->child components

Scoped slots

by Lardpower

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<template id="parent-el">
  <div>
     l1 Parent
     <child>
       l1->2.1 Parent's content for the "default" slot.
       
       <template v-slot:named>
         l1->2.2 Parent's content for the "named" slot.
       </template>
       
       <template v-slot:sc="slotProps">
         l1->2.3 Parent's content for the "sc" slot: 
         {{ slotProps }}.
       </template>
     </child>
  </div>
</template>

<template id="child-el">
  <div>
    l2 Child
    
    <div style="color: red;">
      <slot></slot>
    </div>
    
    <div style="color: green;">
      <slot name="named"></slot>
    </div>
    
    <div style="color: oragne;">
      <slot name="sc" :a="scData" :b="100">
        <h3>SC data: {{ scData }}</h3>
      </slot>
    </div>
  </div>
</template>

<div id="app">
  <parent></parent>
</div>

CSS

body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}

#app {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  transition: all 0.2s;
}

li {
  margin: 8px 0;
}

h2 {
  font-weight: bold;
  margin-bottom: 15px;
}

del {
  color: rgba(0, 0, 0, 0.3);
}

Vue

const child = {
	name: 'child',
  template: $('#child-el').html(),
  data: function(){
  	return {
    	scData : 'Child data l1'
    };
  }
};

const parent = {
	name: 'parent',
  components: {
  	child
  },
  template: $('#parent-el').html()
};

new Vue({
  el: "#app",
  components: {
  	parent,
    child
  },
  data: {
  	
  },
  methods: {

  }
})