我将vue应用程序升级到vue2.7,并希望在vue3中删除应用程序中的槽范围。因此,在示例中,我看到了用于vue2的如下内容:
<ItemList>
<template slot="heading" slot-scope="slotProps">
<h1>My Heading for {{ slotProps.items.length }} items</h1>
</template>
</ItemList>在Vue 3中,它改为:
<ItemList>
<template v-slot:heading="slotProps">
<h1>My Heading for {{ slotProps.items.length }} items</h1>
</template>
</ItemList> 因此,在我的应用程序中,默认情况下使用时隙范围:
<template slot-scope="scope">
...
</template>那么,我如何从我的应用程序中删除插槽范围,对于vue2.7,它是否会得到支持?
发布于 2022-10-13 09:12:09
slot-scope在Vue2中被废弃,并且永远不会返回(即使在Vue3中),语法刚刚发生了变化。
因此,您需要的不是这样写:slot-scope="slotProps",而是需要下面的#default="slotProps"。
所有的细节都可以在这里找到:https://v2.vuejs.org/v2/guide/components-slots.html#Scoped-Slots-with-the-slot-scope-Attribute
#是v-slot的缩写,如这里所解释的:https://v2.vuejs.org/v2/guide/components-slots.html#Named-Slots-Shorthand
https://stackoverflow.com/questions/74053003
复制相似问题