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. java多线程基础(一)--sleep和wait的区别

    sleep和wait的区别有: 1.这两个方法来自不同的类分别是Thread和Object: 2.最主要是sleep方法没有释放锁,而wait方法释放了锁,使得线程可以使用同步控制块或者方法: 3.w ...

  2. Kotlin的特性

    time streams try-with-resources 函数扩展,给types.classes或者interfaces新增方法 null safe 不需要new,后缀声明类型 自动转换有get ...

  3. Amazon S3

    Amazon S3 是什么? Amazon S3 是亚马逊推出的一款存储服务,名为 Amazon Simple Storage Service,即亚马逊简单存储服务. 有些 S3 的概念需要了解一下: ...

  4. 「求助」关于MacOS 适配不了SOIL的问题 以及我自己愚蠢的解决办法

    我的环境 macOS High Sierra 10.13.6 (2018) 我的SOIL源是通过 终端 git clone https://github.com/DeVaukz/SOIL 直接从gay ...

  5. H5 Handlebars的简单使用

    扫码关注公众号,不定期更新干活 web 开发中,js 解析JSON 是经常的事情.非常繁琐.handlebars 使用了模版,只要你定义一个模版,提供一个json对象,handlebars 就能吧js ...

  6. soap天气查询

    public class MainActivity extends AppCompatActivity { private TextView tvContent; @Override protecte ...

  7. ZooKeeper实现生产-消费者队列

    [欢迎关注公众号:程序猿讲故事 (codestory),及时接收最新文章] 生产-消费者队列,用于多节点的分布式数据结构,生产和消费数据.生产者创建一个数据对象,并放到队列中:消费者从队列中取出一个数 ...

  8. 测试常用的sql语句

    1.查询:select * from table_name where 条件语句; SELECT * from sms_runwater WHERE message LIKE "%自有支付% ...

  9. Pyinstaller打包多个.py文件

    https://blog.csdn.net/CholenMine/article/details/80964272

  10. 通过视图实现自定义查询<持续完善中。。。>

    目前实现: ----普通查询路径 /viewShow/viewShow/list.htm ----Echarts查询路劲 /viewShow/viewShow/echarts.htm 1.自定义查询条 ...