render:h => h(App) 是什么意思?

在学习vue.js时,使用vue-cli创建了一个vue项目,main.js文件中有一行代码不知道什么意思。在网上搜索得到如下解答:

参考一:https://www.cnblogs.com/longying2008/p/6408753.html

参考二:https://www.cnblogs.com/whkl-m/p/6970859.html

main.js文件内容

import Vue from ‘vue‘
import App from ‘./App‘

Vue.config.productionTip = false    // 设置false,已阻止vue在启动时生成生产提示

/* eslint-disable no-new */
new Vue({
  el:‘#app‘,
  render: h => h(App)
})

 注:/* eslint-disable no-new */这不是一句注释,在js里面,new一个对象,需要赋值给某个值(变量),用Vue实例化时,不需要赋值给某值(变量),所以需要单独给配一条规则,给new Vue这行代码上面加这个注释,把这行代码规则的校验跳过,通过eslint-disable。是eslint的常用技巧之一。

言归正传:

render: h => h(App)   这是是一个箭头函数是肯定的,那对应的es5形式是怎样的呢???

  如下:

{
   render: h => h(App)
}

  等价于:

{
   render: h =>{
        return h(App)
    }
}

  等价于:

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

  即:

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

  createElement 参数

其实看了createElement的官方文档,我还是不明白createElement的用法。createElement方法的参数有几个?各个参数的含义、类型是什么?

例:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <div id="app"></div>
    <script type="text/javascript" src="https://unpkg.com/vue"></script>
    <script type="text/javascript">
        var app = new Vue({
            el: ‘#app‘, // 提供一个在页面上已经存在的 DOM 元素作为 Vue 实例挂载目标
            render: function (createElement) {
                return createElement(‘h2‘, ‘Hello Vue!‘);
            }
        });
    </script>
</body>
</html>

  

原文地址:https://www.cnblogs.com/carriezhao/p/9289163.html

时间: 2024-08-29 17:50:02

render:h => h(App) 是什么意思?的相关文章

关于Vue中的 render: h =&gt; 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-cli: render:h =&gt; h(App)是什么意思

import Vue from 'vue' import App from './App.vue' Vue.config.productionTip = false new Vue({ render: h => h(App), //生成template(APP) }).$mount('#app') //作用域是'#app' 1.render方法的实质就是生成template模板(在#app的作用域里) 2.render是vue2.x新增的一个函数, 这个函数的形参是h 3.vue调用render

Vue2.0 render:h =&gt; h(App)

首先需要了解这是 es 6 的语法,表示 Vue 实例选项对象的 render 方法作为一个函数,接受传入的参数 h 函数,返回 h(App) 的函数调用结果: 其次,Vue 在创建 Vue 实例时,通过调用 render 方法来渲染实例的 DOM 树: 最后,Vue 在调用 render 方法时,会传入一个 createElement 函数作为参数,也就是这里的 h 的实参是 createElement 函数,然后 createElement 会以 APP 为参数进行调用,关于 createE

Vue2.0 render: h =&gt; h(App)的解释

render: h => h(App)是ES6的写法,其实就是如下内容的简写: render: function (createElement) { return createElement(App); } 官方文档中是这样的,createElement 是 Vue.js 里面的 函数,这个函数的作用就是生成一个 VNode节点,render 函数得到这个 VNode 节点之后,返回给 Vue.js 的 mount 函数,渲染成真实 DOM 节点,并挂载到根节点上. render: functi

h =&gt; h(App)解析

在创建Vue实例时经常看见render: h => h(App)的语句,现做出如下解析: h即为createElement,将h作为createElement的别名是Vue生态系统的通用管理,也是JSX所要求的 h => h(App)是es6语法,即为: function(h){return h(App)}

&lt;h&gt; &lt;/h&gt;、&lt;a&gt;&lt;/a&gt;、&lt;p&gt;&lt;/p&gt;、&lt;img&gt; 、&lt;br&gt;

一.<h></h>(调整字体) 1.<!DOCTYPE html> 2.<html> 3.<head> 4.    <meta charset="utf-8"> 5.    <title></title> 6.</head> 7.<body> <div> <h1>解密大数据</h1> <h2>解密大数据</h2&g

SecureCRT中sqlplus,使用Backspace删除时 ^H^H

平时习惯用Backspace删除输入错误,但是在SecureCRT中使用是,却是: SQL> sele^H^H 网上有几个方法,觉得改SecureCRT的配置最方便.

案例分析丨H&amp;M用设计冲刺将App研发周期缩短为6个月

案例背景 H&M是一家来自瑞典的时装公司,1947年成立.截至2018年6月,H&M 分店遍布全球 68 个国家和地区,分店数目为 4338 间. 作为快速服装生产商,H&M的最大特点之一就是从服装设计到成为专卖店中商品的时间极短.这使得消费者能够更快接触到最前卫的时尚商品.还有助于压缩成本,H&M的产品比定位类似的西班牙品牌Zara还要便宜一些. H&M推出家居系列的时候,为了让用户拥有独特的家居用品购物体验,同时又能够保持其快时尚的品牌声誉,H&M最终决

ACdream原创群赛(13)のwuyiqi退役专场 H Salmon And Cat

H 首先是要姿势正确! 注意完美数的生成机: 2+2a+2b+ab ab都是完美数 假设生成完美数c c = 2 + 2a + 2b + ab c + 2 = ab+2a+2b+4 c + 2 = (a + 2)(b + 2) 然后一开始只有两个完美数1和3. 所以所有的完美数只有质因数分解之后都是类似于 N = (3 ^ x) * (5 ^ y) 但是5不是完美数. 然后就没事了... /**** *COPYRIGHT NOTICE *Copyright (c) 2014 *All right