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. js调试技巧汇总中

    由于设备多样性(PC.ios.安卓.pad.tv)以及各设备对js脚本支持性差异性.js兼容性调试显得越来越重要. 0:尽力模仿真实场景下进行调试,迅速定位问题以及提供解决方案. 1:setTimeo ...

  2. mongodb GUI工具

    人性化,界面工具 网上搜索找的一些 1. 官方网站 tools 2. adminMongo 这个也是我在使用的 3. MongoClient 4. NoSQL Manager for MongoDB ...

  3. MySql (二)入门语句和基本操作

    mysql的入门语句:查看服务器下的库 show databases; 创建库(数据库被创建后它的名字是不可以更改的) create database 数据库名; 2.1.插看当前所在的库 selec ...

  4. MySql学习笔记(四) —— 数据的分组

    前面介绍的聚集函数只是用来计算行数,平均数,最大值,最小值而不用检索所有数据.通过count()函数,我们可以计算生产商1003提供的产品数目,但如果我要查询所有生产商提供的商品数,这就需要进行分组查 ...

  5. Django - 自定义filter

    自定义filter 自定义filter时,使用装饰器fileter 在html中,使用传参方式为: 参数1|函数名:参数2 并且函数和参数之间,不能有空格,如果有空格,会报错. filter和simp ...

  6. swift--字符串替换/过滤/切割

    //替换 var ReplaceString = "http://www.aimonkey.cn"; var FilterReplace = ReplaceString.strin ...

  7. LeetCode_18 4Sum

    Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums s ...

  8. UVA - 12325 Zombie's Treasure Chest (分类搜索)

    题目: 有一个体积为N的箱子和两种数量无限的宝物.宝物1的体积为S1,价值为V1:宝物2的体积为S2,价值为V2.输入均为32位带符号整数.计算最多能装多大价值的宝物,每种宝物都必须拿非负整数个. 思 ...

  9. 每日命令:(6)rmdir

    今天学习一下linux中命令: rmdir命令.rmdir是常用的命令,该命令的功能是删除空目录,一个目录被删除之前必须是空的.(注意,rm - r dir命令可代替rmdir,但是有很大危险性.)删 ...

  10. linux strings-在对象文件或二进制文件中查找可打印的字符串

    推荐:更多Linux 文件查找和比较 命令关注:linux命令大全 strings命令在对象文件或二进制文件中查找可打印的字符串.字符串是4个或更多可打印字符的任意序列,以换行符或空字符结束. str ...