Passing data to your component – slots

There are times when you may need to pass chunks of HTML to your component that are not stored in a property or that you want to format before appearing in the component. Rather than trying to pre-format in a computed variable or similar, you can use slots with your component. 

Slots are like placeholders and allow you to place content between the opening and closing tags of your component and determine where they are going to display. 

A perfect example of this would be a modal window. These normally have several tags and often consist of a lot of HTML to copy and paste if you wish to use it in your application multiple times. Instead, you can create a modal-window component and pass your HTML with ...

Get Vue.js 2.x by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.