VUE中的render:h=>h(App)理解(转)

1、常规写法:
render: function (createElement) {
return createElement(App);
}

2、进一步缩写为(ES6 语法):
render (createElement) {
return createElement(App);
}

3、再进一步缩写为:
render (h){
return h(App);
}

4、按照 ES6 箭头函数的写法,就得到了:
render: h => h(App);

其中 根据 Vue.js 作者 Even You 的回复,h 的含义如下:
It comes from the term “hyperscript”, which is commonly used in many virtual-dom implementations. “Hyperscript” itself stands for “script that generates HTML structures” because HTML is the acronym for “hyper-text markup language”.
它来自单词 hyperscript,这个单词通常用在 virtual-dom 的实现中。Hyperscript 本身是指
生成HTML 结构的 script 脚本,因为 HTML 是 hyper-text markup language 的缩写(超文本标记语言)

Vue.js 里面的 createElement 函数,这个函数的作用就是生成一个 VNode节点,render 函数得到这个 VNode 节点之后,返回给 Vue.js 的 mount 函数,渲染成真实 DOM 节点,并挂载到根节点上。

如果在Vue 1.x下,就应该使用
new Vue({
el: ‘#app’,
components: { App }
});

原文连接:https://segmentfault.com/q/1010000007130348

发布了123 篇原创文章 · 获赞 4 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/yuzhiboyouzhu/article/details/80921705