vue对象render函数的三种实现

更新日期: 2019-09-02阅读: 2.2k标签: 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://www.fly63.com/article/detial/5624

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