Pick Specific Elements From Slot – vue-subslot

vue-subslot is a tiny Vue.js component that can be used to pick up (filter & limit) content from component slots.

Basic usage:

const CardHeader = {
  template: '<div><slot /></div>',
};
const Card = {
  template: `
    <div class="card">
      <div
        v-if="$subslots.cardHeader"
        class="card-header"
      >
        <!-- Pick out the Card Header from the default slot -->
        <subslot name="cardHeader" />
      </div>
      <div class="card-content">
        <!-- Use the remainder -->
        <subslot />
      </div>
    </div>
  `,
  components: {
    Subslot,
    CardHeader,
  },
  mixins: [
    Subslot.define({
      cardHeader: '@CardHeader:1',
    }),
  ],
};
new Vue({
  el: '#app',
  template: `
    <card>
      <!-- The Card Header will be positioned separetely from the content -->
      <card-header>
        My special card
      </card-header>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    </card>
  `,
  components: {
    Card,
    CardHeader,
  }
});

Preview:

Pick Specific Elements From Slot - vue-subslot

Download Details:

Author: privatenumber

Live Demo: https://jsfiddle.net/hirokiosame/tcvp0r98/

Download Link: https://github.com/privatenumber/vue-subslot/archive/develop.zip

Official Website: https://github.com/privatenumber/vue-subslot

Install & Download:

# NPM
$ npm i vue-subslot --save

Add Comment