首页 > 移动平台 > 详细

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

时间:2019-01-25 19:46:51      阅读:213      评论:0      收藏:0      [点我收藏+]

 

 

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)是什么意思

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!