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. STL容器迭代过程中删除元素技巧(转)

    1.连续内存序列容器(vector,string,deque) 序列容器的erase方法返回值是指向紧接在被删除元素之后的元素的有效迭代器,可以根据这个返回值来安全删除元素. vector<in ...

  2. express模块安装使用命令配置

    之前的博客nodejs安装和配置好路径之后就可以安装express了: 随便打开个文件夹右键选择,git bash here 命令行里输入[npm install express -g] -g是全局安 ...

  3. JBoss4.2的启动方式-Jboss无法通过IP地址访问,只能用localhost访问

    JBOSS版本:4.2.3GA症状:服务器无法通过IP地址去访问,只能用127.0.0.1或者localhost来访问. 开始怀疑是端口没有放开,用telnet ip 80 也不能连接,就一直怀疑端口 ...

  4. vuex的各个细节理解(因人而异)

    应用级的状态集中放在store中: 改变状态的方式是提交mutations,这是个同步的事物: 异步逻辑应该封装在action中. const vuex_store = new Vuex.store( ...

  5. 4星|《OKR工作法》:关注公司的真正目标,以周为单位做计划和考核

    本书篇幅比较小,两个小时就可以看完.主要内容讲OKR工作法的基本概念,然后用一个虚拟的创业公司的创业故事来演示实施OKR过程中可能遇到的问题.OKR给创业带来的好处. OKR工作法相对来说是比较简单的 ...

  6. oracle数据库过期

    本文转载自http://soft.chinabyte.com/database/6/12320006.shtml[来源:比特网 作者:悠虎] 由于Oracle11G的新特性所致,经常会遇到使用sqlp ...

  7. MySQL学习笔记(十二)__连接查询(一)

    连接查询含义:又称多表查询,当查询的字段来自多个表时,就会用到连接查询 笛卡尔乘积现象:表1 有 m 行,表2 有 n 行,结果 = m*n 行发生原因:没有有效的连接条件如何避免:添加有效的连接条件 ...

  8. Jmeter的属性和变量

    jmeter的属性和变量可以简单理解为编程里面的全局变量和局部变量.属性是全局可见,可以跨线程组传递调用,而变量基本上只能存在于一个线程组中(在测试计划定义的变量也是可以跨线程组传递的).同线程组内的 ...

  9. chr()返回值是当前整数对应的 ASCII 字符。

    #chr() 用一个范围在 range(256)内的(就是0-255)整数作参数,返回一个对应的字符.#返回值是当前整数对应的 ASCII 字符.1 import random input_m =10 ...

  10. spring aop 方法增加日志记录

    使用场景: 1:调用外部接口时需要记录出参和入参. 2:分布式系统之间,调用各个系统之间需要记录日志,一旦出现了问题也可以找得到元数据 一言不合,上代码: # 枚举类 package xxxxxxxx ...