Declaring templates and elements inside of templates works great for most scenarios. Sometimes you need a bit more control over what your component will do with the props and children it receives, so Vue provides a render function that allows you complete programmatic control over every argument using JSX.

We have a parent component which renders:

        <Content slot="content" :limit="4">
<div><img src="https://robohash.org/mindy?set=set4" alt=""></div>
<div><img src="https://robohash.org/john?set=set4" alt=""></div>
<div><img src="https://robohash.org/kim?set=set4" alt=""></div>
<div><img src="https://robohash.org/joel?set=set4" alt=""></div>
<div><img src="https://robohash.org/maggie?set=set4" alt=""></div>
</Content>

Content.vue:

<script>
import { shuffle } from "lodash"
export default {
functional: true,
render: (createElement, { children, props, data }) => {
if(props.limit) {
return createElement('div', data, shuffle(children.slice(0, props.limit)));
} else {
return createElement('div', data, shuffle(children));
}
}
}
</script>

You can also using JSX:

最新文章

  1. 用Jedis连接Redis
  2. css伪类选择器及伪元素选择器
  3. mongoDB研究笔记:分片集群部署
  4. ahjesus可供C#使用的ip地理位置查询插件
  5. informatica 学习日记整理
  6. HTML5革命即将爆发
  7. divcss5布局
  8. java 类型转json格式
  9. Android 线程Thread的2种实现方法
  10. oracle的to_number、to_char、to_date用法
  11. Java中内存空间的分配及回收
  12. 迁移/home目录至新硬盘分区总结--无备份情况下
  13. 得到client真IP住址
  14. Vulkan Tutorial 22 Index buffer
  15. NSNotification
  16. Linux系统常用命令权威指南
  17. linkin大话面向对象--接口
  18. mysql索引sql优化方法、步骤和经验
  19. Unity实现c#热更新方案探究(二)
  20. scrapy爬虫学习系列三:scrapy部署到scrapyhub上

热门文章

  1. 待销售分拣单App数据推送
  2. Java编程思想读书笔记_第三章
  3. R语言曲线拟合函数(绘图)
  4. Spring+Spring MVC+Hibernate环境搭配
  5. CAD隐藏或显示工具条上的按钮(com接口VB语言)
  6. 删除链表中重复的结点_java
  7. 05Microsoft SQL Server 表创建,查看,修改及删除
  8. HDU6189 Law of Commutation (数论)
  9. 【Hadoop】二、HDFS文件读写流程
  10. &lt;MySQL&gt;入门六 变量