How can i clone a vue application to another dom node?
I have made a simple vue app to work out my problem, i tried cloning using js clone function and re-initializing the application, it will mount but it wont workout the events. Here's my code:
const initMyApp = (el) => {
return new Vue({
el,
data: {
message: 'HEY'
},
methods: {
sayHello: function () {
this.message = 'HELLO!!!' + new Date().getMilliseconds()
}
},
mounted: function () {
console.log('mounted')
}
})
}
initMyApp('#app')
function moveApp() {
var appNode = document.getElementById("app")
var cloned = appNode.cloneNode(true);
document.getElementById("appContainer").innerHTML = ''
document.getElementById("appContainer").appendChild(cloned);
initMyApp('#appContainer')
}
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<div id="app">
<h2>Main</h2>
<button @click="sayHello">Hello</button>
<p>{{message}}</p>
</div>
<button onclick="moveApp()">DO</button>
<div>
<h2>Container</h2>
<div id="appContainer">
</div>
</div>
Any suggestion is really appreciated