vue, how dynamically, programically, on click add component to the DOM specific place? vue, how dynamically, programically, on click add component to the DOM specific place? vue.js vue.js

vue, how dynamically, programically, on click add component to the DOM specific place?


By the help of this: https://stackoverflow.com/a/2925633/7741865 and by dynamically creating the child components, you should achieve what you want. Sample:

addContainer() {  // dynamically create component, replace 'Child' with your component  var ComponentClass = Vue.extend(Child);  var instance = new ComponentClass();  instance.$mount();  // get the caret position and insert component at that place  var sel, range;  if (window.getSelection) {    sel = window.getSelection();    if (sel.getRangeAt && sel.rangeCount) {      range = sel.getRangeAt(0);      range.deleteContents();      range.insertNode(instance.$el);      // remove the highlight (if you want)      window.getSelection().removeAllRanges();    }  }}

SANDBOX