[Vuejs]-VueJS โ€“ create component programmatically by name

0๐Ÿ‘

you are right is a simple js.

look at the example below, most importend thing is eval()

class Polygon {
  constructor(height, width) {
    this.height = height;
    this.width = width;
  }
  
  get getHeight() {
    return  this.height
  }
}

// js string code
var code = "new Polygon(15, 200)";
// convert it to code;
var cls = eval(code);

console.log(cls.getHeight)

0๐Ÿ‘

I found that using

this.$options.__proto__.components['MyComponent1']

works and do what I want. Is it the cleanest solution ?

Leave a comment