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
        }
    })
  • 相关阅读:
    FTPClient使用中的问题--获取当前工作目录为null
    MGR安装
    脚本在Shell可以执行成功,放到crontab里执行失败
    使用Python通过SMTP发送邮件
    MySQL Router
    事务管理(ACID)
    mysqldump使用
    MySQL InnoDB Cluster
    Linux LVM逻辑卷配置过程详解(创建、扩展、缩减、删除、卸载、快照创建)
    centos命令行控制电脑发出滴滴声
  • 原文地址:https://www.cnblogs.com/samve/p/9960963.html
Copyright © 2011-2022 走看看