How it works...

When you build a component that you want to reuse or you want others to reuse, you will have some parts that behave in a generic way. In our box, for example, the message was customizable, so we can reuse it in other parts of a program with different messages. We used a slot so that the user has complete freedom on what to put inside (even another component). The cancel button, instead, is better controlled by props, so we do not have to pass an entire button into a slot every time, we just pass true or false.

Another concern is that our component needs to talk with the external world; in the confirmation box case, it needs to tell the main program whether the user clicked on OK or Cancel. This is best done through events. ...

Get Vue.js 2 Cookbook 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.