Vue.js 技术揭秘学习 (3) render
Vue 的 _render 方法是实例的一个私有方法,它用来把实例渲染成一个虚拟 Node ,返回的是一个VNode
在 Vue 的官方文档中介绍了 render 函数的第一个参数是 createElement,那么结合之前的例子:
<div id="app">
{{ message }}
</div>
相当于我们编写如下 render 函数:
render: function (createElement) {
return createElement('div', {
attrs: {
id: 'app'
},
}, this.message)
}
再回到 _render 函数中的 render 方法的调用:
vnode = render.call(vm._renderProxy, vm.$createElement)
可以看到,render 函数中的 createElement 方法就是 vm.$createElement 方法:
export function initRender (vm: Component) {
// ...
// bind the createElement fn to this instance
// so that we get proper render context inside it.
// args order: tag, data, children, normalizationType, alwaysNormalize
// internal version is used by render functions compiled from templates
vm._c = (a, b, c, d) => createElement(vm, a, b, c, d, false)
// normalization is always applied for the public version, used in
// user-written render functions.
vm.$createElement = (a, b, c, d) => createElement(vm, a, b, c, d, true)
}
实际上,vm.$createElement 方法定义是在执行 initRender 方法的时候,可以看到除了 vm.$createElement 方法,还有一个 vm._c 方法,它是被模板编译成的 render 函数使用,而 vm.$createElement 是用户手写 render 方法使用的, 这俩个方法支持的参数相同,并且内部都调用了 createElement 方法。
#总结
Vue.js 技术揭秘学习 (3) render的更多相关文章
- Vue.js 技术揭秘学习 (2) Vue 实例挂载的实现
Vue 中我们是通过 $mount 实例方法去挂载 vm 的 $mount 方法实际上会去调用 mountComponent 方法,mountComponent 核心就是先实例化一个渲染Watcher ...
- Vue.js 技术揭秘学习 (1) new Vue 发生了什么
Vue 初始化主要就干了几件事情,合并配置,初始化生命周期,初始化事件中心,初始化渲染,初始化 data.props.computed.watcher 等等.
- Vue.js 技术揭秘(学习) vue流程
new Vue() _init() mergeOptions $watch --> new Watch vm._render 生成VNode create diff patch vm._upda ...
- Vue.js 技术揭秘(学习) slot
slot特性分发父组件的内容 作用域插槽:通过子组件的一些数据来决定父组件实现插槽
- Vue.js 技术揭秘(学习) 深入响应式原理 nextTick外传
microTask mutationObserve. promise.then macroTask setImmediate. messageChannnel.setTimeout.postMess ...
- 详解Vue.js 技术
本文主要从8个章节详解vue技术揭秘,小编觉得挺有用的,分享给大家. 为了把 Vue.js 的源码讲明白,课程设计成由浅入深,分为核心.编译.扩展.生态四个方面去讲,并拆成了八个章节,如下: 准备工作 ...
- Vue.js 2.0 学习重点记录
Vue.js兼容性 Vue.js.js 不支持 IE8 及其以下版本,因为 Vue.js.js 使用了 IE8 不能模拟的 ECMAScript 5 特性. Vue.js.js 支持所有兼容 EC ...
- Vue.js 源码学习笔记
最近饶有兴致的又把最新版 Vue.js 的源码学习了一下,觉得真心不错,个人觉得 Vue.js 的代码非常之优雅而且精辟,作者本身可能无 (bu) 意 (xie) 提及这些.那么,就让我来吧:) 程序 ...
- Vue.js 源码学习笔记 -- 分析前准备1 -- vue三大利器
主体 实例方法归类: 先看个作者推荐, 清晰易懂的 23232 简易编译器 重点: 最简单的订阅者模式 // Observer class Observer { constructor (d ...
随机推荐
- cmd开启3389
如何用CMD开启3389与查看3389端口 开启 REG ADD HKLM\SYSTEM\CurrentControlSet\Control\Terminal" "Server / ...
- 学习wavenet_vocoder之预处理、训练
一.预处理 1.在进行预处理时,如果不明白需要的参数,可以使用命令获取帮助,从这里我们可以看到可以具体的用法和对应的参数. python preprocess.py --help python pre ...
- SpringBoot:初识SpringBoot
西部开源-秦疆老师:基于SpringBoot 2.1.6 的博客教程 秦老师交流Q群号: 664386224 未授权禁止转载!编辑不易 , 转发请注明出处!防君子不防小人,共勉! 1.SpringBo ...
- 转: Github上关于iOS的各种开源项目集合
https://blog.csdn.net/jiashaoying/article/details/79079500 下拉刷新 EGOTableViewPullRefresh - 最早的下拉刷新控件. ...
- optistruct线性求解一次二次单元应力位移比较
通过分析比较10mm.5mm.3mm.1mm的网格模型, 网格越细密: 位移与应力均趋于恒定值(收敛): 一次与二次单元的应力区域一致: 一次与二次单元的位移相差11.3%,一次单元的位移小. 所用的 ...
- The Linux usage model for device tree data
Linux and the Device Tree The Linux usage model for device tree data Author: Grant Likely grant.like ...
- PANIC: Missing emulator engine program for ‘x86’ CPU.
参考链接:https://zhidao.baidu.com/question/652153765084187325.html 解决方案:看图最上面路径,进入你的文件夹下,把红文件夹 ( 1 ) 中的所 ...
- 阶段1 语言基础+高级_1-3-Java语言高级_03-常用API第二部分_第4节 System类_3_System类的常用方法
复制数组
- Jmeter之Switch Controller
在测试过程中,各种不同的情况需要执行不同的操作,这个时候用if控制器比较麻烦,此时就可以使用Switch Controller代替. 一.界面显示 二.配置说明 1.名称:标识 2.注释:备注 3.S ...
- 【BASIS系列】SAP 中查看account登陆次数及时间的情况
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[BASIS系列]SAP 中查看account登 ...