I have a project where I am using Sage Roots (v10), with Vue js (v3).
I have been successful in bringing in Vue and mounting the App.vue (Single Page Component) onto a root element in side the app.blade.php file:
app.js
import App from './App.vue'
const app = createApp(App)
app
.use(router)
.mount('#wp-vue-app');
app.blade.php
<div id="wp-vue-app">
<!-- App.vue renders here -->
</div>
But now I want to render components via php inside the root element <div id="wp-vue-app"> with Global components:
app.js
import Header from './components/Header'
import router from "@scripts/router";
const app = createApp({})
app
.component('MainHeader', Header)
.use(router)
.mount('#wp-vue-app');
app.blade.php
<div id="wp-vue-app">
<MainHeader :menu-items="{{ @json_encode(wp_get_nav_menu_items('main-menu')) }}" />
</div>
But this does not appear to work, and I cannot figure out why. Vue appears to remove all the content between the <div id="wp-vue-app"></div>.
I thought it might be the way the component is registered, or the way I have called the createApp(). I haven't been able to find anything useful when it comes to SPA's.
Any help would be appreciated!