Module 9 - slots Flashcards

1
Q

what are slots?

A

slot enables us to receive markup and vue code and place it instead of where we put the slots tag in the component that we pass the markup to.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are named slots?

A

If you have more than 1 slot in a component you need to give the slots a name with a name attribute so you can set the dynamic content in the right place. You can have one unnamed slot and that would be the default slot.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the difference between slots and props?

A

props are used to pass data from outside of a component while slots are used in order to receive html+vue and place it instead of the slot tag

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you pass markup to a named slot?

A

In order to pass html into a named slot you need to wrap it in a template tag and give it a v-slot directive with the value of the named slot. for example :

(template v-slot=”nameOfSlot)
content
(/template)

content that is not wrapped in the template will go to the default template implicitly. you can make it explicit by placing the rest of the content in a template with v-slot=default

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is v-slot used for

A

v-slot:”slotName” is a directive that you add to a template tag in order to assign the markup content in that template to a named slot.

Another usage is to pass props (data) from the component that has the slot to the component that uses the slot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What happens if you put html markup between slot tags?

A

The markup is used as a default value in case no markup is sent to the slot.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what is this.$slots

A

$slots is a property provided by vue that holds information about the slots data that the component has.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the shorthands for v-slot?

A

instead of v-slot:somename you can use #somename

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are scoped slots?

A

scoped slots allow you to pass data from inside the component that has the slot to the component that uses the slot and passes the markup

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you pass the data from a scoped slot to the component that provides the markup?

A

In order to pass data from the slot to the component that is passing the markup to the slot you need to put a named attribute in the slot and bind it to the data.

(slot :item=”dataName”)(/slot)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you use the data passed from the component with the slot in the component passing the markup

A

In order to use the data from the component that has the slot in the component that passes the markup you need to wrap it in tag and on it use the v-slot directive and assign to it all of the props passed from the component that has the slot. for example:

component with slot
(slot v-bind:item=”goal” anotherItem=”…”)(/slot)

component with markup:
(template v-slot:default=”slotProps”)
(p) {{slotProps.goal}} (/p)
(/template)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Is there a shortcut for scoped slots if we only target the default slot

A

If we only target the default slot as a scoped slot we can omit the template tag and place the #default=”slotProps” directly on the markup

How well did you know this?
1
Not at all
2
3
4
5
Perfectly