Skip to content
Advertisement

In Vue2.7, v-slot is not available, how to solve the problem?

When I run the following code, I get the following results (Google Chrome running screenshot).

JavaScript

The running result is as follows:

enter image description here

When I use v-slot, the code is as follows:

JavaScript

The running result is as follows:

enter image description here

So in Vue2.7, v-slot is not available, how to solve the problem?

Advertisement

Answer

Your syntax is correct, except one little detail: you can’t use camelCase for slot names.
To be fair, I don’t precisely know why, it has to do with template compilation and with the fact the slot names get parsed as element attributes in <template v-slot:slot-name"scope">. Vue’s styling guideline does strongly advise on using kebab-case for attributes, directives and the likes, when used in templates or JSX.
However, name="slotName" + <template #slot-name="scope"> doesn’t seem to work for slots.

In short, name="slotName" (+ <template #slotName="scope") does not work, but name="slot-name" (+ <template #slot-name="scope") does.

See it working, in Vue 2.7.7:

JavaScript
JavaScript

Notes:

  • :planAll="" is shorthand for v-bind:planAll=""
  • <template #slot-name=""> is shorthand for <template v-slot:slot-name="">
  • when you only have one slot, you can remove the slot name altogether (it defaults to name="default")
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement