Vue slot slot

Simple to use 1 slot

vue example:

image

myTemplate component template:

image

html:

image

SUMMARY my-template tag will replace the contents of the tag myTmplate assembly slot, my-template tag if nothing else, the default display myTmplate tag assembly slot.

2 named slots

myTemplate component template:

image

html:

image

By adding the name attribute to myTemplate assembly slot tag specifies a custom name

And add the attribute to the slot my-template tag button tag, a name attribute is a value of a tag slot, in order to cover the corresponding slot label

3 Scope slot

myTemplate component template:

image

html:

image

Data Sources:

image

Role: to change the display mode subassemblies content through parent component

In myTemplate slot assembly to label binding custom attributes (data) through, and data (goodList) bound up. ( : Data = "goodList" )

My-template external to the contents of the tag tag (Template) to define the slot-scope binding property scope, value of slot

And through the slot. [Slot label bound custom property name data] to obtain data (slot.data).

Guess you like

Origin www.cnblogs.com/chujunqiao/p/11807021.html