1.组件学习之内容分发

1.1 作用域插槽

父级

<div class="parent">
<child>
<template scope="props">
<span>hello from parent</span><br/>
<span>{{ props.text }}</span><br/>
    <span>{{ props.text2 }}</span><br/>
    <span>{{ props.text3 }}</span>
</template>
</child>
</div>

子级模板

<div class="child"> 
<span>first hello</span>
<slot text="hello from child" text2="hello again"></slot> 
<slot text3='hello!!!!'></slot>
</div>

其中child组件首先会调用模板,然后在使用child组件时标签内的template部分将会被渲染到子组件child的slot标签中。

scope 的值对应一个临时变量名(保存的是对象),此变量接收从子组件中传递的 prop 对象,每个slot会产出一个prop对象,在这里就分别是{text:'hello from child',text2:'hello again'}和{text3:'hello!!!!'},每个slot都会用template渲染一次,最终完成渲染。

注:对于组件将要分发的内容,如果没有指定slot名字(不是具名slot),那么分发的内容将会在子组件中的每个slot中都进行渲染。

输出结果是

first hello
here is parent
hello from child
hello again
here is parent hello!!!!

  

最新文章

  1. [Leetcode] Bulls and Cows
  2. Unable to the boot Simulator ! Mac开机现“CoreTelephony Trace File Error”,
  3. 如何优雅的使用vue+vux开发app -02
  4. CSS三列布局
  5. java使用IO读写文件总结
  6. iOS Swift最简单的Animation
  7. MOOCULUS微积分-2: 数列与级数学习笔记 1. Sequences
  8. candence 知识积累1
  9. Web项目中创建简单的错误处理页面
  10. centOS学习part4:安装配置vsftp
  11. java中一直说一个汉字使用两个字节,原来是不准确的
  12. 我的CSS架构
  13. windows phone (18) Border元素
  14. appfog java jdbc mysql连接
  15. IBase&lt;T&gt;
  16. Effective Java 第三版——88. 防御性地编写READOBJECT方法
  17. kubebapps 添加私有harbor 中的helm repo
  18. poj3104(二分)
  19. Unity关于方法事件生命周期官方文档
  20. Mysql导入脚本失败,提示需要SUPER权限

热门文章

  1. python day 12: 选课系统
  2. 关于阿里 iconfont 的使用步骤
  3. CentOS 7 - 安装PostgreSQL
  4. CRM, C4C和SAP Hybris的数据库层设计
  5. django learn step
  6. Redis3.2集群部署安装
  7. python内置异常层次
  8. net 与或非
  9. WebSocket转载
  10. 关于SpringBoot下template文件夹下html页面访问的一些问题