vue对象render函数的三种实现

摘要:第一种方式($createElement),h是一个函数类型变量。第二种方式:createElementFunction 是一个函数类型变量;第三种写法:es6语法之箭头函数
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://shenqiku.cn/article/FLY_5624