Render functions open up a world of customization and control by using pure JavaScript rather than Vue's templating language. When you need to pull off something super custom (or maybe you're just coming from React-land) you can turn to Render functions to save the day. This pattern demonstrates something very similar to a "bind" effect in a Vue template, but allows much finer control and customization.

We can use render props pattern in Vue as well:

const Selected = {
props: {
render: {
default: h => null
}
},
data() {
return {
selected: 0
};
},
methods: {
select(val) {
this.selected = val;
}
},
render() {
return this.$props.render({
selected: this.selected,
select: this.select
});
}
};
export default {
functional: true,
render: (h, { props }) => (
<div>
<Selected
render={({ select, selected }) => {
return (
<div>
<label class="block text-grey-darker text-sm font-bold mb-2">
Select Cat:
<input
type="number"
value={selected}
onChange={event => select(+event.target.value)}
class="shadow appearance-none border rounded w-full py-2 px-3 text-grey-darker leading-tight"
/>
</label>
<div>
<CatsList
names={props.names}
num={props.num}
select={select}
selected={selected}
/>
</div>
</div>
);
}}
/>
</div>
)
};

[Vue @Component] Pass Vue Render Functions as Props for Powerful Patterns的更多相关文章

  1. [Vue @Component] Pass Props Between Components with Vue Slot Scope & renderless component

    Components with slots can expose their data by passing it into the slot and exposing the data using  ...

  2. [Vue @Component] Pass Props to Vue Functional Templates

    Functional templates allow you to create components consisting of only the template tag and exposing ...

  3. [Vue @Component] Extend Vue Components in TypeScript

    This lesson shows how you can extend and reuse logic in Vue components using TypeScript inheritance. ...

  4. [Vue @Component] Load Vue Async Components

    Vue provides a straight-forward syntax for loading components at runtime to help shave off initial b ...

  5. [Vue @Component] Write Vue Functional Components Inline

    Vue's functional components are small and flexible enough to be declared inside of .vue file next to ...

  6. [Vue @Component] Dynamic Vue.js Components with the component element

    You can dynamically switch between components in a template by using the reserved <component>  ...

  7. [Vue @Component] Simplify Vue Components with vue-class-component

    While traditional Vue components require a data function which returns an object and a method object ...

  8. 前端框架vue.js系列(9):Vue.extend、Vue.component与new Vue

    前端框架vue.js系列(9):Vue.extend.Vue.component与new Vue 本文链接:https://blog.csdn.net/zeping891103/article/det ...

  9. vue component :is

    vue component :is Vue <component> element https://vuejs.org/v2/guide/components.html#Dynamic-C ...

随机推荐

  1. 通过重写.htaccess文件添加404

    如果说是用linux服务器的系统 想要给自己的网站设置404怎么弄?如果你不会给自己的Ecs服务器添加服务器管理系统,或是你购买的云虚拟主机没有304.404设置,那么就要通过自己重写文件来设置404 ...

  2. jboss解决ip访问受限问题

    jboss启动后,localhost可以访问,127.0.0.1可以访问,但是内网ip却访问不了,比如ip是192.168.1.2,这个192.168.1.2就访问不到web页面 解决方案: jbos ...

  3. js判断是安卓 还是 ios webview

    判断原理:JavaScript是前端开发的主要语言,我们可以通过编写JavaScript程序来判断浏览器的类型及版本.JavaScript判断浏览器类型一般有两种办法,一种是根据各种浏览器独有的属性来 ...

  4. 梦想CAD控件安卓控件事件

    MxDrawActivity.commandEvent 命令调用事件. 参数 说明 int iCommand 命令ID,这个ID用户自已来取的,只要多个命令ID不重复就可以 代码实现如下: publi ...

  5. java虚拟机(六)--垃圾收集器和内存分配策略

    目前没有完美的收集器,不同的厂商.版本的虚拟机提供的垃圾收集器会有很大的差别,用户根据自己应用特点和要求组合出各个年代所使用 的收集器.基于jdk1.7Update14之后的虚拟机. HotSpot的 ...

  6. jQuery鼠标划入划出

    今天来简单的谈谈jQuery的一个划入划出的方法,.首先划入划出能想到的东西有哪些呢,. 1:hover 2:mouseenter/mouseleave 3:mouseover/mouseout. 一 ...

  7. 【2018百度之星资格赛】 A 问卷调查 - 位运算&动规

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6344 参考博客:在此感谢http://www.cnblogs.com/LQLlulu/p/941923 ...

  8. Python&机器学习总结(一)

    ① numpy中np.c_和np.r_ np.r_是按列连接两个矩阵,就是把两矩阵上下相加,要求列数相等,类似于pandas中的concat(). np.c_是按行连接两个矩阵,就是把两矩阵左右相加, ...

  9. [Algorithm] 4. Ugly Number II

    Description Ugly number is a number that only havefactors 2, 3 and 5. Design an algorithm to find th ...

  10. 分金币 (UVA 11300)

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33899 思路:推公式,发现可以转化为求给定n个数,求到所有点距离之和最小的点 ...