Vue中的slot(占坑,预留位置)

  1. 子模板不使用slot
  2. 子模板使用slot
  3. 子模板使用使用name属性,且传递data
  • 文件名:Slots.vue
//slot组件
<template>
  <div class="Slots">
      <div class="myd">
      在子组件中不使用slot时SlotChildwithnoslots下的内容不会显示
      <SlotChildwithnoslots>         
          <div class="no-name">111111111111111111我是嵌在子组件内不具有属性名的标签</div>
          <div >2222222222222222222222222222我是嵌在子组件内不具有属性名的标签</div>
      </SlotChildwithnoslots>
    </div>
      '
      '
      '
      '
      '
      '
      '
      <div class="myd">'
      在子组件中使用slot时SlotChildwithslots下的内容会显示
       <SlotChildwithslots>         
          <div class="no-name">111111111111111111我是嵌在子组件内不具有属性名的标签</div>
          <div >2222222222222222222222222222我是嵌在子组件内不具有属性名的标签</div>
      </SlotChildwithslots>
      </div>  
        '
      '
      '
      '
      '
      '
      '.
       <div class="myd">'
      在子组件中使用slot时且包含数据时下的内容会显示
       <SlotChildwithslotsanddata>         
          <div slot="header">111111111111111111我是嵌在子组件内不具有属性名的标签</div>
          <div slot="header">2222222222222222222222222222我是嵌在子组件内不具有属性名的标签</div>
          <template slot-scope="user">
                <div v-for="item in user.data" :key="item.id">
                {{item}}
                </div>
            </template>
      </SlotChildwithslotsanddata>
      </div>  
       
  </div>
</template>
<script>
import SlotChildwithnoslots from '@/components/SlotChildwithnoslots'
import SlotChildwithslots from '@/components/SlotChildwithslots'
import SlotChildwithslotsanddata from '@/components/SlotChildwithslotsanddata'
export default {
    name: 'Slots',
    components:{
        SlotChildwithnoslots,
        SlotChildwithslots,
        SlotChildwithslotsanddata
    },
    data () {
        return {
      
        }
    }
}
</script>
<style>
.myd
background-color:yellow;
height: 300px;
border:1px solid red;
}
</style>
 
  • 文件名:SlotChildwithslots.vue
//slot的子组件
<template>
<div class="SlotChildwithslots">
<slot></slot>
我是slot的子组件
</div>
</template> <script>
export default {
name: 'SlotChildwithslots',
data () {
return { }
}
}
</script>
  • 文件名:SlotChildwithnoslots.vue
//slot的子组件
<template>
<div class="SlotChildwithnoslots">
我是slot的子组件
</div>
</template> <script>
export default {
name: 'SlotChildwithnoslots',
data () {
return { }
}
}
</script>
  • 文件名:SlotChildwithslotsanddata.vue
//slot的子组件
<template>
<div class="SlotChildwithslotsanddata">
<slot name="header" ></slot> 我是slot的子组件
<slot :data="user"></slot>
</div>
</template> <script>
export default {
name: 'SlotChildwithslotsanddata',
data () {
return {
user: [
{name: 'Jack', sex: 'boy'},
{name: 'Jone', sex: 'girl'},
{name: 'Tom', sex: 'boy'}
]
}
}
}
</script>
 

Vue中的slot(占坑,预留位置)的更多相关文章

  1. 记录vue中一些有意思的坑

    记录vue中一些有意思的坑 'message' handler took 401ms 在出现这个之前,我一直纠结于 是如何使用vue-router或者不使用它,通过类似的v-if来实现.结果却出现这个 ...

  2. vue中的slot与slot-scope

    深入理解vue中的slot与slot-scope vue+element-ui+slot-scope或原生实现可编辑表格 vue插槽详解

  3. vue中的slot理解和使用

    最近被vue 搞得一塌糊涂,理解的比较慢,工作进度进度要求太快,需求理解不明,造成了很大的压力. 在理解Vue中的Slot的时候看了网上的相关内容,看了半天没看到明白说的是什么,然后自己就安装了vue ...

  4. Vue中的slot

    个人理解:是对组件的扩展,通过slot插槽向组件内部指定位置传递内容,通过slot可以父子传参: Slot的通俗理解 是“占坑”,在组件模板中占好了位置,当使用该组件标签时候,组件标签里面的内容就会自 ...

  5. vue 中的slot属性(插槽)的使用

    总结如下: VUE中关于插槽的文档说明很短,语言又写的很凝练,再加上其和方法,数据,计算机等常用选项在使用频率,使用先后上的差别,这就有可能造成初次接触插槽的开发者容易产生“算了吧,回头再学,反正已经 ...

  6. vue中的slot(插槽)

    vue中的插槽----slot 什么是插槽? 插槽(Slot)是Vue提出来的一个概念,正如名字一样,插槽用于决定将所携带的内容,插入到指定的某个位置,从而使模板分块,具有模块化的特质和更大的重用性. ...

  7. 深入理解vue中的slot与slot-scope

    from:https://segmentfault.com/a/1190000012996217?utm_source=tag-newest 写在前面 vue中关于插槽的文档说明很短,语言又写的很凝练 ...

  8. 如何使用Vue中的slot

    之前看官方文档,由于自己理解的偏差,不知道slot是干嘛的,看到小标题,使用Slot分发内容,就以为 是要往下派发内容.然后就没有理解插槽的概念.其实说白了,使用slot就是先圈一块地,将来可能种花种 ...

  9. Vue中的slot内容分发

    ①概述: 简单来说,假如父组件需要在子组件内放一些DOM,那么这些DOM是显示.不显示.在哪个地方显示.如何显示,就是slot分发负责的活. ②默认情况下 父组件在子组件内套的内容,是不显示的. 例如 ...

随机推荐

  1. manifest.json 解析--手机web app开发笔记(三-2)

    四.SDK配置和模块权限配置 SDK 就是 Software Development Kit 的缩写,中文意思就是“软件开发工具包”,也就是辅助开发某一类软件的相关文档.范例和工具的集合都可以叫做“S ...

  2. [Spring cloud 一步步实现广告系统] 17. 根据流量类型查询广告

    广告检索服务 功能介绍 媒体方(手机APP打开的展示广告,走在路上看到的大屏幕广告等等) 请求数据对象实现 从上图我们可以看出,在媒体方向我们的广告检索系统发起请求的时候,请求中会有很多的请求参数信息 ...

  3. java Timer工具类实现定时器任务

    第一 schedule 方法 三个参数 按照顺序 (执行的任务方法,开始执行时间,多少时间后循环去执行)  代码可用 public class TestScheedule { public stati ...

  4. DedeCMS 5.7 sp1远程文件包含漏洞(CVE-2015-4553)

    DedeCMS 5.7 sp1远程文件包含漏洞(CVE-2015-4553) 一.漏洞描述 该漏洞在/install/index.php(index.php.bak)文件中,漏洞起因是$$符号使用不当 ...

  5. 洛谷 P3203 [HNOI2010]弹飞绵羊

    题意简述 有n个点,第i个点有一个ki,表示到达i这个点后可以到i + ki这个点 支持修改ki和询问一点走几次能走出所有点两个操作 题解思路 分块, 对于每个点,维护它走到下一块所经过的点数,它走到 ...

  6. python2.7官方文档阅读笔记

    官方地址:https://docs.python.org/2.7/tutorial/index.html 本笔记只记录本人不熟悉的知识点 The Python Tutorial Index 1 Whe ...

  7. web项目jsp中无法引入js问题

    https://blog.csdn.net/C1042135353/article/details/80274685#commentBox 这篇文章超赞的,几个小时的时间看了这篇文章豁然开朗,瞬间懂了 ...

  8. NVIDIA: Failed to initialize NVML: driver/library version mismatch

    [NVIDIA驱动:Failed to initialize NVML: driver/library version mismatch] 原因:Ubuntu16.04 装新驱动时,会报以上错误,定位 ...

  9. MySQL多表关联数据同时删除

    MySQL多表关联时的多表删除: DELETE t1, t2FROM    t1LEFT JOIN t2 ON t1.id = t2.idWHERE    t1.id = 25

  10. unity_UGUI养成之路03

    关卡分页设计 功能1:通过直接滑动: 添加自动排序组件 设置通过添加组件设置内容的滑动,多余内容的隐藏   功能2:通过点击下面的圆圈滑动 上述代码实现: using UnityEngine;usin ...