美文网首页
Vue 中的插槽使用

Vue 中的插槽使用

作者: 最尾一名 | 来源:发表于2019-04-26 17:36 被阅读0次

前言

在 Vue 项目中,使用到 slotslot-scope 的情况很多,特别是在表格中,但是官方文档说的不太容易理解,所以写这篇文章来记录一下我的学习成果。

匿名插槽

匿名插槽不具有 name 属性,在组建中最多只能有一个。

// child.vue
<template>
  <div class="child">
    <slot></slot>
</template>
// father.vue
<child>
  This is slot content
</child>

这样,在父组件中就能够通过匿名插槽渲染内容。

具名插槽

省略掉

作用域插槽

在 2.6.0 以后的版本已废弃的写法:

// child.vue
<template>
  <div class="child">
    <slot name="test" :uer="user"></slot>
</template>

<script>
export default {
  data() {
    return {
      user: ['Rain', 'Cruise', 'XiaoMing']
    }
  }
}
</script>
<child>
  <template slot="test" slot-scope="scope">
    {{ scope.user }}
  </template>
</child>

相关文章

  • 18、Vue3 作用域插槽

    作用域插槽:让插槽内容能够访问子组件中,vue2中作用域插槽使用slot-scope,vue3中使用v-slot ...

  • (十八)补充-Vue3中插槽的使用

    本章我们将了解到的是vue3中常用插槽的使用; vue3中的插槽是在用的时候和vue2的区别略有不同,常见插槽使用...

  • vue插槽

    vue插槽slot的理解与使用 vue slot插槽的使用介绍及总结

  • vue 插槽的使用

    vue 插槽手册 深入理解vue中的slot与slot-scope 插槽的使用其实是很简单首先要明白插槽是使用在子...

  • 2020-07-23 一次性讲明白vue插槽slot

    vue插槽slot 一、前言 vue官方文档中在"组件基础"内容中提到组件可以通过插槽分发内容,那插槽是怎么使用的...

  • vue插槽slot

    vue插槽slot 一、前言 vue官方文档中在"组件基础"内容中提到组件可以通过插槽分发内容,那插槽是怎么使用的...

  • 详解vue中的插槽

    1.在vue中插槽分为具名插槽和非具名插槽;而插槽的使用主要是我们在页面中存在很多个相似但却重复的部分; 首先我以...

  • vue 作用域插槽(插槽赋值)

    使用vue开发时,组件插槽slot是我们经常使用的特性之一,有时我们插槽中的自定义内容需要使用组件中的数据,这时就...

  • vue中的slot(插槽)

    vue中的插槽————slot 什么是插槽? 插槽(Slot)是Vue提出来的一个概念,正如名字一样,插槽用于决定...

  • Vue 中的插槽使用

    前言 在 Vue 项目中,使用到 slot、slot-scope 的情况很多,特别是在表格中,但是官方文档说的不太...

网友评论

      本文标题:Vue 中的插槽使用

      本文链接:https://www.haomeiwen.com/subject/kqyqnqtx.html