I am using vue3-sfc-loader (https://github.com/FranckFreiburger/vue3-sfc-loader) to register and load .vue components that works fine:
sample 1
<div id="app">
<ae-studio></ae-studio>
</div>
<script>
const app = Vue.createApp({});
app.component('ae-studio', loadVM("/components/aeStudio.vue"));
const vueInstance = app.mount("#app");
</script>
sample 2
<template>
<div>
append studio header
</div>
<table style="width:100%;">
<tr>
<td style="width:50%">
<ae-nav></ae-nav>
</td>
<td style="width:50%">
<ae-docsview></ae-docsview>
</td>
</tr>
</table>
</template>
<script>
app.component('ae-nav', loadVM("/components/aeNav.vue"));
app.component('ae-docsview', loadVM("/components/aeDocsview.vue"));
</script>
they are working but I need to dynamically add a component to the page like this :
<template>
<button @click="show('this is a message')">Click to add Component here</button>
<div id="comPlace">A place for new component</div>
</template>
<script>
app.component('ae-test', loadVM("/components/aeTest.vue"));
export default {
setup(props) {
return {
show: (msg) => {
console.log(msg);
let cPlace = document.getElementById("comPlace");
cPlace.innerHTML='<ae-test>qqqqqqqqqqqqqqqqqqq</ae-test>';
let a = app.component('ae-test', loadVM("/components/aeTest.vue"));
}
};
}
}
</script>
Above code is not working. I tried forceUpdate but the issue not resolve. How can I resolve this? I created a repository on github that you can use it for tracking the issue.
You can use
componentin vue 3and you can use
Vue.defineAsyncComponentupdated full code here.