Subscribe on changes!

v-bind different behavior with slot name

avatar
Jun 1st 2023

Vue version

https://github.com/vuejs/core/tree/a95e612

Link to minimal reproduction

https://template-explorer.vuejs.org/#eyJzcmMiOiI8c2xvdFxyXG4gIG5hbWU9XCJ4eHh4eHhcIlxyXG4+XHJcbjwvc2xvdD5cclxuXHJcbjxzbG90XHJcbiAgOm5hbWU9XCJ4eHh4eHhcIlxyXG4+XHJcbjwvc2xvdD5cclxuXHJcbjxzbG90XHJcbiAgOltgbmFtZWBdPVwieHh4eHh4XCJcclxuPlxyXG48L3Nsb3Q+XHJcblxyXG48c2xvdFxyXG4gIHYtYmluZD1cIntcclxuICAgIG5hbWU6IHh4eHh4eFxyXG4gIH1cIlxyXG4+PC9zbG90PlxyXG4iLCJzc3IiOmZhbHNlLCJvcHRpb25zIjp7Im1vZGUiOiJmdW5jdGlvbiIsImhvaXN0U3RhdGljIjp0cnVlLCJjYWNoZUhhbmRsZXJzIjp0cnVlLCJzY29wZUlkIjoic2NvcGUtaWQiLCJpbmxpbmUiOnRydWV9fQ==

Steps to reproduce

// work well, slot name customNamee
<slot
  name="customNamee"
>
</slot>

// work well, slot name customNamee
<slot
  :name="customNamee"
>
</slot>

// Deviate from expectations, work as name with deualt
<slot
  :[`name`]="customNamee"
>
</slot>

// Deviate from expectations, work as name with deualt
<slot
  v-bind="{
    name: customNamee
  }"
></slot>

What is expected?

all some, slot name with customNamee

What is actually happening?

different

System Info

No response

Any additional comments?

No response

avatar
Jun 5th 2023

@zhangenming The third gets converted to fourth one ie, third and fourth are same

<slot v-bind="{ name: customName }"></slot>

Here you are passing 'name' as a data to the slot content.

Also, your expression does not specify the slot name. which can be specified by 'name' attribute to slot tag. Since it is missing, by convention it is considering it as 'default'.

This is not a bug!

avatar
Jun 15th 2023

v-bind={key:x, ref:x} Both key and ref are effective, so it is unreasonable for name alone not to be effective

avatar
Jun 18th 2023

The name of the slot is a special attribute. It is handled specially during compilation, so it cannot be added dynamically.

avatar
Jun 19th 2023

The name of the slot is a special attribute. It is handled specially during compilation, so it cannot be added dynamically.

At least this should work, It can be done at compile time

  v-bind="{
    name: customNamee
  }"
></slot>```
avatar
Jun 19th 2023

@zhangenming Like @shaileshnighojkar said:

you are passing 'name' as a data to the slot content.

Most developers think so, don't they? It's technically possible, but it's not worth it and this change may even be a breaking change. IMO, If a slot has a name, it should be clearly defined, which is good practice.

avatar
Jun 19th 2023

In my opinion, v-bind={is,key,ref,name}, this all four should behave the same