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. SQL数据库,增加查询修改以及防sql写入攻击

    SQL添加信息 SQL查询信息 SQL修改信息 SQL语句写入攻击: 普通语句添加信息 sql写入语句攻击: 解决方法:分开传送语句与参数关键:@

  2. ASP.NET文件操作

    在开发Web程序时,不但有存储在数据库中和XML文件中的数据形式需要处理,而且还有很多诸如文本.Word文档和图片等格式的文件数据需要处理.尤其是在一些信息管理系统中,文档的处理流程贯穿了整个系统的运 ...

  3. 微信JSSDK支付

    var appId,timeStamp,nonceStr,package,signType,paySign; function goumai(){ $.confirm({ title: '确认购买', ...

  4. python __slots__ 详解(上篇)

    转自:http://blog.csdn.net/sxingming/article/details/52892640 python中的new-style class要求继承Python中的一个内建类型 ...

  5. phpcms标签第三弹

    {CHARSET}  -------------------------------------字符集 (gbk或者utf-8) {if isset($SEO['title']) && ...

  6. iframe子页面让父页面跳转 parent.location.href

    if ($roleNum < 9) { echo "<script > parent.location.href='admin_login.php' </script ...

  7. javascript入门经典(第五版)-清华出版社之“经典”错误

    学校教材太烂,于是自己买书. 果然是入门经典,开篇就把我惊着了~ 第九页≯1.4/ch1_example2.html / <script> //script block 2 documen ...

  8. (转) 淘淘商城系列——Redis的安装

    http://blog.csdn.net/yerenyuan_pku/article/details/72849612 通过上文的学习,我相信大家已经将首页的轮播图展示出来了,接下来我们将进入一个新的 ...

  9. sql IIF函数的应用

    工作中由于用各种框架,业务也不是很复杂,一直没怎么写过复杂的sql,今天写了一个 数据如下 代码如下 Sub 班级分数等级分析(shname) Dim Con As Object, rs As Obj ...

  10. arx升级

    如果你打算升级你的ARX或者想在同一个IDE(譬如vs2010)编译多个版本的ARX,那么我希望这篇帖子对你有帮助首先你应该简单了解Objectarx开发的版本对应情况:R15   --- 2000- ...