vue对象render函数的三种实现

更新日期: 2019-09-02阅读: 2.7k标签: render
import App from './app.vue' 

const root = document.createElement('div');
document.body.appendChild(root);


第一种方式($createElement):

//写法三:
const rootVue = new Vue(
    {   
        router: vueRouter,
        render: function () {
       // return  this.$createElement('p', 'hi');
         const h = this.$createElement; //h是一个函数类型变量
         return h(App);
        }
    }
   ).$mount(root)


第二种方式:

new Vue(
 {  
      //createElementFunction 是一个函数类型变量
     render: function (createElementFunction) {
         return createElementFunction(App);
     }
  }
).$mount(root)

 

第三种写法:

new Vue(
  {  //es6语法之箭头函数
      render: (h) => h(App)
  }
).$mount(root)

本文内容仅供个人学习/研究/参考使用,不构成任何决策建议或专业指导。分享/转载时请标明原文来源,同时请勿将内容用于商业售卖、虚假宣传等非学习用途哦~感谢您的理解与支持!

链接: https://fly63.com/article/detial/5624

内容以共享、参考、研究为目的,不存在任何商业目的。其版权属原作者所有,如有侵权或违规,请与小编联系!情况属实本人将予以删除!