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. 创建maven项目遇到的问题

    1.新建完成的maven项目,缺少src/main/java 解决方案:把项目中的jre换成eclipse中默认的jre. 另外还可以参考:解决Eclipse建立Maven项目后无法建立src/mai ...

  2. 动态排序JavaBean

    Java中如果对对象排序可以考虑实现Comparable接口,但是需要排序的属性一旦指定就不能再修改.BeanUtils组件提供了对JavaBean动态排序的支持,即可以在运行时指定排序的属性.实例运 ...

  3. Squid 正向代理

    实现通过特定设备对特定的网址访问加速 使用squid 正向代理 实现,区别于反向代理,两者区别的根本在于作为中转的服务器在一个完整的请求中是代表客户端还是代表服务器. 服务端设置 1.安装程序包(推荐 ...

  4. Objective-C中copy 、retain以及ARC中新加入的strong、weak关键字的含义

    copy: 创建一个引用计数为1的对象,然后释放旧的对象 retain:释放旧的对象,将旧对象的值赋予输入对象,再提高输入对象的引用计数为 1 Copy其实是建立了一个相同的对象,而retain不是: ...

  5. C++ 程序的编译

    一.编译器都具备集成开发环境(Integrated Developed Environment,IDE) 二.程序源文件命名约定: C++ 的后缀一般是 .cpp .cc .C .cpp .cxx 三 ...

  6. axios方法get及post代码示例

    show: function(){ //get方式 //赋值给变量self var self = this; var url = "hotcity.json"; axios.get ...

  7. CAD使用GetAllAppName读所有名称(网页版)

    主要用到函数说明: MxDrawEntity::GetAllAppName 得到所有扩展数据名称,详细说明如下: 参数 说明 [out, retval] IMxDrawResbuf** ppRet 返 ...

  8. 微服务网关从零搭建——(三)Ocelot网关 + identity4

    增加验证服务 1.创建名为AuthService 的core 空项目 2.修改startup文件 using System; using System.Collections.Generic; usi ...

  9. react antD moment

    import moment from 'moment' console.log(moment().add(1, 'days').format('YYYY-MM-DD')) //当前时间前一天 cons ...

  10. Python 爬虫爬取今日头条街拍上的图片

    # 今日头条--街拍 import requests from urllib.parse import urlencode import os from hashlib import md5 from ...