Embed Vue applications within the container of the main Vue application

My goal is to establish a foundational Vue application that offers essential features such as signing in, navigating with a sidebar, and the flexibility to interchange navbar items. I envision creating separate Vue applications for each navbar item.


Main concept: The plan is to provide a REST API and a fundamental container (Vue app) capable of rendering other Vue apps within a specific div element. This setup will enable others to incorporate their own frontend apps and interact with the API if needed. Instead of creating numerous apps from scratch, the primary objective is to develop a highly modular administration system with a seamless Plug and Play system. A registration process will be implemented for custom apps, allowing the API to recognize these apps along with their base URLs so that my base app can retrieve them.


Setting up the base app

The base app will have a route for custom apps

{
  path: '/app/*',
  component: CustomAppContainer,
},

and will display this view

<template>
  <div id="customAppContainer">Render custom apps here</div>
</template>

The navbar will contain a link /app/one to navigate and render the 'one' app in the customAppContainer.


Configuring custom apps

When defining routes for custom apps, the base URL needs to be specified

export default new Router({
  base: '/one/',
  routes: [
    {
      path: '/',
      component: Home,
    },
  ],
});

In the main.js, updating it like this may be necessary

new Vue({
  router,
  render: h => h(CustomAppContainer),
}).$mount('#customAppContainer');

However, the challenge lies in ensuring that the app recognizes the CustomAppContainer and #customAppContainer.


Another consideration is how to distribute when only having some index.html files and needing to integrate one into another. How can a base app be deployed so that when a user wants to access a custom app via /app/myCustomApp, it gets mounted into the customAppContainer?

An example akin to this scenario is illustrated in Nextcloud

During Vue app development, running it as a standalone entity is feasible. However, for production purposes, the plan involves moving files from the dist folder into an apps directory. Upon launching the base container application, it should automatically detect all sub-applications present.

If more details are required, please feel free to request!

Answer №1

1

There seems to be an issue with Vue recognizing CustomAppContainer

Try adding

import CustomAppContainer from "path/to/CustomAppContainer.vue"
in a .vue file.


2

Vue is not able to recognize #customAppContainer

The selector should be in index.html. If your selector is within CustomAppContainer, try adding something like

<div id="#app"></div>
in index.html (usually in /public folder) and replace .$mount('#customAppContainer'); with .$mount('#app');.


3

VUE router needs the <router-view> tag. Try using this markup:

<!-- In the template, all page content goes here -->
<template>
  <!-- Navigation section -->
  <nav>
    <!-- Router links that render as "a" elements -->
    <router-link to="/one">Go to /one</router-link>
    <!-- Alternatively, standard HTML tags can also be used -->
    <a href="/two">Go to /two</a>
  </nav>
  <!-- The chosen component picked by the router will go here (Home.vue) -->
  <router-view/>
</template>

4

Router.js requires an import:

import Home from "path/to/the/Home.vue"
export default new Router({
  base: '/one/',
  routes: [
    {
      path: '/',
      component: Home,
    },
  ],
});

If everything looks okay, you're good to go!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Passing variables from AJAX response to PHP using a passthru function

In my PHP file, I have implemented a functionality where certain checkboxes are checked and upon clicking a button, a JavaScript file is triggered. The JavaScript code snippet used is as follows: $.ajax ({ type: "POST", url: "decisionExec.php", ...

Vuetify: Responsive v-date-picker width for v-dialog and v-menu

I am looking to create an adaptive date picker using v-date-picker. When the page is viewed on a phone, I want the date picker to open in a v-dialog, and when viewed on a desktop, I want it to open in a v-menu. Here is my attempt: <template> < ...

Transforming Uint8Array into BigInt using Javascript

I've come across 3 different ways to convert a Uint8Array to BigInt, but each method seems to produce varying results. Can someone clarify which approach is correct and recommended? Utilizing the bigint-conversion library. The function bigintConversi ...

What could be causing my Ajax function to malfunction?

I've been attempting to incorporate a form that sends two javascript variables to a php script and displays the result in a new Div on the same page using an ajax function. Unfortunately, it's not functioning as expected. Here is the code snippe ...

Learn the best way to retrieve the highest number from a Array<String> in TypeScript or JavaScript

Can someone help me create a function in JS or TS that meets the following requirements? I am looking for a functional programming approach. ・Input type: Array(String) ・Output type: string or undefined Examples Input Result ["" ...

Incorporating an HTTP header into d3.json using queue.js

I know that I can include a header in a D3 JSON request by using the following code: d3.json("http://localhost:8080/data") .header("Application-ID", "1") However, I'm uncertain about how to add this header when utilizing queue's defer method. ...

Unraveling JSON data within an AngularJS controller

I'm facing an issue with exposing a field in my AngularJS controller. The problem arises when a JSON 'owner' object is returned by a webservice, containing a field named 'Cave'. If this 'Cave' field has a null, empty, or ...

Is it possible to drag the div container in HTML to resize its width from both left to right and right to left?

After posing my initial inquiry, I have devised a resizing function that allows for the expansion of a div's width. When pulling the right edge of the div to resize its width from left to right, is it possible to adjust the direction or how to resize ...

Nesting objects within arrays using Typescript Generics

Hello, I am currently attempting to assign the correct type to an object with nested values. Here is a link to the code in the sandbox: https://codesandbox.io/s/0tftsf interface Product { name: string, id: number productList?:ProductItem[] } interf ...

How can you make each <li> in an HTML list have a unique color?

Looking for a way to assign different colors to each <li> element in HTML? <ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> <ul> Here's how you want them displayed: Item 1 should be red Ite ...

NgOnChanges replaces form control value when user inputs text

In my autocomplete form control component: @Component({ selector: 'app-autocomplete', templateUrl: './app-autocomplete.view.html', changeDetection: ChangeDetectionStrategy.OnPush, }) export class AutoCompleteFilterComponent ...

Django views are not receiving multiselect data from Ajax requests

As a newcomer to Django, I am still learning the ropes. One challenge I am facing involves a multiselect list on my webpage. I need to send the selected items to my views for processing, and I attempted to accomplish this using Ajax. However, it seems that ...

Bring in SASS variables to enhance Material UI theme in NextJS

Within my project, I currently have the following two files: materialTheme.ts import { createMuiTheme, Theme } from "@material-ui/core/styles"; const theme: Theme = createMuiTheme({ palette: { primary: { main: "#209dd2", contras ...

Is the system failing to produce a validation error for a JSON object array when it's supposed to?

When I make a post request to api/record, it is supposed to detect validation errors in the intentionally set JSON data: Vue Post Request this.$http({ method: 'POST', url: 'api/record', data: { emotions: [{'id& ...

The replace function fails to recognize Cyrillic characters when combined with the /b flag

Struggling with a persistent issue, I've noticed that my code works perfectly with Latin characters but fails to recognize Cyrillic characters when using jQuery. $('p').each(function() { var $this = $(this); $this.html($this.text().re ...

Trouble updating document with MongoDB updateOne when using ID as filter

I need to update a property value of a specific document by sending a request to my NextJs API using fetch. // Update items in state when the pending time in queue has passed, set allowed: true items.map((item) => { const itemDate = new Date(item.adde ...

What is the process for exporting a chart into Excel?

My current challenge involves displaying data extracted from a database in the form of a bar chart and then exporting both the data and the chart as an image into an Excel file. While I have successfully displayed the bar chart, I am facing difficulties in ...

"Although both jQuery and PHP are capable of setting the element attribute, it is only PHP that functions successfully

I have been trying to set an element attribute to adjust the range of a slider. Initially, I used ajax to fetch data from a php file and assign it to the attribute. The slider looked good with the value but unfortunately, it wasn't functioning as expe ...

What could be causing Typed.js to not function properly in my situation?

Having an issue with typed.js not functioning properly. Here is the code snippet: <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="js/jquery-1.11.3.min.js"></script> <!-- Include all compiled plugins ...

Navigating to a different page on Vue2 with routes

I am struggling with redirecting to another Vue page from my script code. I tried using router.push() but it's not directing me to the desired Vue page. Here is a snippet of my source code: src/router/index.js import Vue from 'vue' import ...