vue2 cross-component value transfer and transparent transmission ($attrs and $listeners)

When used within a Vue.js component, $attrs and $listeners provide a convenient way to handle the attributes and event listeners passed to the component.

1.$attrs is an object that contains props passed by the parent component to the current component but not declared by the current component. This is useful for implementing "transparent transmission".

2.$listeners is also an object. It contains all event listeners passed by the parent component to the current component.

Example:

  Pass value down: $attrs

  Ye components:

  Parent component:

 

Subassembly :

Upload the value:

Ye components:

Parent component: 

 

 

Subassembly:
 

Guess you like

Origin blog.csdn.net/qq_36657291/article/details/131656768