关于 slot, slot-scope 和 v-slot

相同点:

它们都是 VUE 提供的用来获取当前作用域内容的。

不同点:

2.6.0 中,vue 官方为具名插槽和作用域插槽引入了一个新的统一的语法 (即 v-slot 指令)。它取代了 slot 和 slot-scope。

也就是说如果你 vue 的版本是2.6.0+ 的就要使用 v-slot
在这里插入图片描述
下面我来介绍具体使用上的区别

  • slot,slot-scope
<template slot="order" slot-scope="scope"><!-- 这里也可以简写为 #order='scope' -->
     <el-tag size="mini" v-if="scope.row.cat_level === 0">一级</el-tag>
     <el-tag type="success" size="mini" v-else-if="scope.row.cat_level === 1">二级</el-tag>
</template>
  • v-slot
<template v-slot:order="scope"><!-- 这里也可以简写为 #order='scope' -->
     <el-tag size="mini" v-if="scope.row.cat_level === 0">一级</el-tag>
     <el-tag type="success" size="mini" v-else-if="scope.row.cat_level === 1">二级</el-tag>
</template>

上述代码实现的效果一样

注意:‘order’ 是自定义的插槽名字

关于插槽的深入理解 请参考官网:https://cn.vuejs.org/v2/guide/components-slots.html

猜你喜欢

转载自blog.csdn.net/l1830473688/article/details/107502133