Home > Mobile >  How to remove slot-scope in vue2.7
How to remove slot-scope in vue2.7

Time:10-13

I upgraded my vue application to vue2.7 and I want to remove slot-scope from my application as it is removed in vue3. So in the examples, I see this for vue2:

<ItemList>
  <template slot="heading" slot-scope="slotProps">
    <h1>My Heading for {{ slotProps.items.length }} items</h1>
  </template>
</ItemList>

In Vue 3 it is changed to this:

<ItemList>
  <template v-slot:heading="slotProps">
    <h1>My Heading for {{ slotProps.items.length }} items</h1>
  </template>
</ItemList> 

So in my application slot-scope is used in default:

<template slot-scope="scope">
...
</template>

So how can I remove slot-scope from my application and also for vue2.7, will it be supported?

CodePudding user response:

slot-scope was deprecated in Vue2 and will never return back (even in Vue3), the syntax has just changed.

So rather than writing this: slot-scope="slotProps" you need to have the following #default="slotProps".

All the details are available here: https://v2.vuejs.org/v2/guide/components-slots.html#Scoped-Slots-with-the-slot-scope-Attribute


# being a shorthand for v-slot as explained here: https://v2.vuejs.org/v2/guide/components-slots.html#Named-Slots-Shorthand

  • Related