zoukankan      html  css  js  c++  java
  • 关于Vue中的 render: h => h(App) 具体是什么含义?

    render: h => h(App) 是下面内容的缩写:

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

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

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

    再进一步缩写为:

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

    按照 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 的缩写(超文本标记语言)


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

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

    还有另外一种写法效果是一样的:

    import App from './App'
    new Vue({
        el: '#root',
        template: '<App></App>',
        components: {
            App
        }
    })
  • 相关阅读:
    服务器图片等资源在8080端口保存
    thinkphp 3.2.1 URL 大小写问题 下面有具体说明
    linux samba smb 在客户端无法连接使用
    php连接redis服务
    服务器死机 导致 mongo 挂掉
    同一个页面引用不同版本jquery库
    CSS3阴影 box-shadow的使用和技巧总结
    php 中使用正则
    Hbase-1.1.1-java API
    hive1.2.1问题集锦
  • 原文地址:https://www.cnblogs.com/samve/p/9960963.html
Copyright © 2011-2022 走看看