Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to mount two seperate applications inside one Vue project?

I am creating a frontend and a backend application inside one Vue 3 project. Everything works fine except that app.js is throwing following error, depending on which component is visited in the browser.

I you visit the app.vue:

[Vue warn]: Failed to mount app: mount target selector "#cms" returned null.

and if you visit the cms.vue:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[Vue warn]: Failed to mount app: mount target selector "#app" returned null.

The mounting file app.js looks like this:

require('./bootstrap');

import {createApp} from 'vue';
import app from "../vue/app";
import cms from "../vue/cms";
import router from "./router";

createApp(app)
    .use(router)
    .mount("#app");

createApp(cms)
    .use(router)
    .mount("#cms");

Is there any way I can prevent the browser warning?

>Solution :

You could query the document for those elements, and only mount the ones that exist:

const appEl = document.querySelector('#app');
if (appEl) {
  createApp(app).use(router).mount(appEl);
}

const cmsEl = document.querySelector('#cms');
if (cmsEl) {
  createApp(cms).use(router).mount(cmsEl);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading