码迷,mamicode.com
首页 > 移动开发 > 详细

vue-cli: render:h => h(App)是什么意思

时间:2019-01-25 20:05:29      阅读:467      评论:0      收藏:0      [点我收藏+]

标签:oct   生成   utf-8   tps   mount   false   template   lang   als   

 

 

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方法时, 会传入一个createElement函数作为参数(也就是h的实参是createElement函数)

4、createElement用于在页面中创建元素

5、createElement以App为参数进行调用, 即把App的内容创建到页面中的‘#app‘作用域里

 

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

等价于

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

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

 

示例

<!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>

结果

技术分享图片

 

vue-cli: render:h => h(App)是什么意思

标签:oct   生成   utf-8   tps   mount   false   template   lang   als   

原文地址:https://www.cnblogs.com/qq254980080/p/10321288.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!