We have a web app that uses Vue as the front end framework.
This web app has a text editor, and as part of the functionality of the text editor, it will add custom HTML to the editable area (a contenteditable div.)
The editor can add HTML which is a Vue component but I need some way of compiling the Vue component before/after inserting it into the DOM.
For example, let's assume we have a contenteditable div like so:
<div contenteditable="true">
<p>Some text</p>
</div>
Now, on a user action, after the <p> tag, the editor will insert an Vue component.
<div contenteditable="true">
<p>Some text</p>
<custom-gallery></custom-gallery>
</div>
<custom-gallery></custom-gallery> is a Vue component. How do I 'execute' this component so it renders the HTML, event handlers etc?
One idea I had is to insert an element like:
<div contenteditable="true">
<p>Some text</p>
<div class="custom-gallery"></div>
</div>
and then execute this:
import Vue from 'vue'
import CustomGallery from './path/to/components/CustomGallery.vue'
new Vue({
el: document.querySelector(".custom-gallery"),
render: h => h(CustomGallery)
})
Would that be the best way? Will that work if it's already inside a Vue application?