The Big Photo
A tile is small. In this exercise, the selected photo shows big, over the whole page. Galleries call this a lightbox: the page stays behind it, darker, and a button closes it.
The component. Lightbox.vue is new. Its template has the dark layer over the page (the class lightbox), a white box in it (box), and in the box, the close button ✕ (the class close). The styles are ready. The lightbox has no photo of its own: what it shows comes from App.vue, through slots.
- The default slot gets the photo itself: the emoji in a
divwith the classbig, with the photo's color as its background. The classbigis instyle.css, because the content of a slot is styled by the parent, not by the lightbox. - A slot named
caption, in a paragraph with the classcaptionunder the photo, gets the caption and the place, for exampleSunrise, Loch Lomond.
The close button belongs to the lightbox. It doesn't hide anything itself: it emits the event close, and App.vue decides what happens.
The task. When a photo is selected, App.vue shows the lightbox with it. When the lightbox emits close, App.vue hides it, and no photo is selected any more.
A tip: show the lightbox with v-if. While it's hidden, it isn't on the page at all, and when it's shown, a photo is selected, so its content can use that photo.
Instructions
- 1
When a photo is selected, show the lightbox, with the photo big in its default slot.
- 2
Show the photo's caption and place in the lightbox's slot named
caption. - 3
A click on
✕closes the lightbox: the lightbox emitsclose, andApp.vuehides it, with no photo selected.