[Vuejs]-Passing object to props in a View instance > dynamically load Component from external variable

0👍

import Vue from 'vue'

export function createComponent(selector, propsData) {

  let instance = new Vue({
    el: document.createElement('div'),
    render(createElement) {
     return createElement(
      'h' + this.level,   // tag name
      this.$slots.default // array of children
     )
    },
    propsData
  })

  document.body.querySelector(selector).appendChild(instance.$el);
}

Assuming that you want to create dynamically VueJS instance and append it to dom. Also propsData object you need to move out from render function. Render function is optional, you can always use template string…

Leave a comment