vue main.js 中 render: h => h(App) 具体含义解释

原文连接:vue

  1. https://github.com/ly525/blog/issues/90
  2. https://segmentfault.com/q/1010000007130348?_ea=3899677

请解释:render: h => h(App) 这段话的意思?webpack

# main.js
new Vue({
    el: '#app',
    router: router,
    store: store,
    render: h => h(App)
})

为了方便仍然有疑惑的人,贴一个连接, 其中 @bjunc 的解答能够做为该题的完美回答;git

大概的翻译下: render: h => h(App) 是下面内容的缩写:github

render: function (createElement) {
    return createElement(App);
}

进一步缩写为(ES6 语法):web

render (createElement) {
    return createElement(App);
}

再进一步缩写为:segmentfault

render (h){
    return h(App);
}

按照 ES6 箭头函数的写法,就获得了:babel

render: h => h(App);

其中 根据 Vue.js 做者 Even You 的回复,h 的含义以下:app

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".dom

它来自单词 hyperscript,这个单词一般用在 virtual-dom 的实现中。Hyperscript 自己是指 生成HTML 结构的 script 脚本,由于 HTML 是 hyper-text markup language 的缩写(超文本标记语言)函数

我的理解:createElement 函数是用来生成 HTML DOM 元素的,也就是上文中的 generate HTML structures,也就是 Hyperscript,这样做者才把 createElement 简写成 h。

相关文章
相关标签/搜索