I need the sidebar to be visible across all interfaces

https://i.stack.imgur.com/iEgAF.png

I have developed a website for employee monitoring with six interfaces. The first interface is for sign-up, the second for logging in, the third for creating projects, the fourth for displaying projects, the fifth for creating tasks, and the sixth for viewing tasks. I have also created a sidebar that I want to appear on all interfaces except for sign-up and log-in pages. Here is the code structure using router-view: App.vue:

<template>
  <v-app>
        <router-view></router-view>
  </v-app>
</template>
<script>
export default {
  components:{

  }
}
</script>

The sidebar component was implemented separately in navbar.vue file to be displayed across all interfaces: navbar.vue:

<template>
  <v-app>
    <div class="main-sidebar-container">
      <div class="main-sidebar-container_content">
        <v-navigation-drawer class="deep-purple accent-4" dark permanent>
          <div class="main-sidebar-container_content_header">
            <img class="logo" src="../../../src/assets/logo_base.png" />
          </div>

          <v-divider></v-divider>

          <div class="sidebar-search">
            <div class="cu2-search_simple-layout cu2-search">
              <div class="cu2-search__inner ">
                <div class="cu2-search__icon icon">
                  <svg class="ng-star-inserted">
                    <use
                      xlink:href="https://app.clickup.com/map.e7a227c29e2316abeae1.svg#svg-sprite-cu3-search"
                    ></use>
                  </svg>
                </div>
              </div>
            </div>
          </div>

         <div class="cu2-search__text"> Search </div>

          <v-list>
            <v-list-item v-for="item in items" :key="item.title" class="twoSection" link>
              <v-list-item-icon>
                <v-icon>{{ item.icon }}</v-icon>
              </v-list-item-icon>

              <v-list-item-content>
                <v-list-item-title>{{ item.title }}</v-list-item-title>
              </v-list-item-content>
            </v-list-item>
          </v-list>

          <template v-slot:append>
            <div class="pa-2">
              <v-btn block>
                Logout
              </v-btn>
            </div>
          </template>
        </v-navigation-drawer>
      </div>
    </div>
  </v-app>
</template>

<script>
export default {
  data() {
    return {
      drawer: true,
      items: [
        { title: "Home", icon: "mdi-home-city" },
        { title: "Notifications", icon: "mdi-account" },
        { title: "Pulse", icon: "mdi-account-group-outline" },
        { title: "Goals", icon: "mdi-account" },
        { title: "Show less", icon: "mdi-account-group-outline" }
      ],
      mini: true,
    };
  },
};
</script>

<style scoped>
.main-sidebar-container {
  left: 0;
  top: 0;
  bottom: 0;
  height: 100%;
  width: 60%;
  position: fixed;
  z-index: 1;
  top: 0;
  overflow-x: hidden;
}
.main-sidebar-container_content {
  width: 50%;
  height: 100%;
}

...

main.js:

import Vue from 'vue'
import App from './App.vue'
import vuetify from './plugins/vuetify';
import VueRouter from "vue-router";
import { routes } from "./router";
import axios from "axios";
import { store } from './store/index';
import Vuelidate from "vuelidate";
import 'material-design-icons-iconfont/dist/material-design-icons.css'

Vue.config.productionTip = false
Vue.use(VueRouter);
Vue.use(Vuelidate);

axios.defaults.baseURL = "localhost:4000/api/services";
axios.defaults.headers.common["Authorization"] =
  ....

Answer №1

If you want to incorporate your navbar component into the App.vue file, you can do so by following these steps:

Firstly, make sure to add the necessary code within the template section:

<template>
  <v-app>
     <div>
        <div class="flex w-full overflow-auto h-screen bg-page">
            <navbar class="w-full flex-1 max-w-72"/>
            <div class="px-4 flex-1 max-h-screen overflow-auto">
                <div class="pb-16">
                    <router-view></router-view>
                </div>
            </div>
        </div>  
 </v-app>
</template>
<script>
    import navbar from './navbar'
    export default {
      components:{
       navbar
      }
    }

</script>

However, keep in mind that if you want the sidebar to disappear during login and signup views, you will need to implement specific handling for those scenarios.

There are various options available to achieve this desired behavior, so explore different approaches before making a decision.

Answer №2

To display the navigation component on every page, you must import it into each page.

For example, if your navigation file is named TheNavigation.vue, include the following code snippet in the template of each interface where you want the component to appear:

<div style="text-align: center;">
           <TheNavigation />
        <transition name="fade" mode="out-in">
          <router-view :key="$route.path" />
        </transition>
 </div>

In the script section, import the component as shown below:

<script>
import TheNavigation from '../components/TheNavigation.vue';
import axios from "axios";
export default {
     components: {
    TheNavigation
  },
    data() {
    }
  }
 </script>

Let me know if this solution works for you! Feel free to ask for further explanation. Ensure to specify the correct relative path when importing the navigation component in the script!

Answer №3

My previous approach in React.js involved creating a Menu Component and using it with each MenuItem component. For example, for the Home MenuItem or other components, you can include the Menu component within the MenuItem Component.

It would look something like this:

const Menu = () => {
    return <div>{...Menu}</div>
}

const HomeMenuItem  = () => {
    return (
        <div>
            <Menu />
            
            <div>
            {...insert menu content here!}
            </div>
        </div>
    )
}

This same technique can be applied to any other menuItem - it may seem like a workaround, but it does get the job done.

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

The pseudo-element ::before did not function as expected in the CSS code

I attempted to utilize the ::before element in HTML directly. Below is my code: <ul class="clear toogled" style="height:188pxl"> <li tabindex="0" style="display: block;"> <label for="MAP-IA_1_1_OR_CB_1" aria-label="Filter by product"> :: ...

information not adhering to the text field

I'm having some trouble with Vue as I try to bind the result to a textarea: <textarea class="form-control" id="test" rows="6" v-model="test"></textarea> data: { test: '' } axios({ method: 'po ...

"Exploring the Power of Vue 3 Event Bus Through the Composition API

I recently set up mitt and I'm facing difficulties dispatching events to another component. The issue arises due to the absence of this in the setup() method, making it challenging to access the app instance. Here's my current approach: import A ...

The issue with the CSS combination of :after and :hover:after across different HTML elements

Encountering an issue while attempting to create a rollover effect using CSS :after and :hover pseudo-elements. Check out the clock and facebook icons on the right side by visiting: See below for the CSS code: .icon { background: url('. ...

Outside drop shadows in CSS3 creates an interesting visual effect by giving

I am currently using the following CSS styling for a list of li items. border: 1px solid black; border-radius:10px; box-shadow: 8px 8px 4px #666; -o-box-shadow: 10px 10px 5px #888; -icab-box-shadow: 10px 10px 5px #888; -khtml-box-shadow: 10px 10px 5px #8 ...

Cypress .type is failing to properly update the v-model value in my Vue3-powered form

login.vue - this file represents the login page component <template> <v-container id="login-page"> <v-row> <v-col> <input id="username" v-model="username" data-cy="username&q ...

Arrangement of tables using HTML and CSS on the outdoor patio

Looking for advice on how to align buttons in the last column of a table outside of the table but in the same row. The attached image shows the current layout: https://i.sstatic.net/Ex5AR.png ...

Tips for vertically aligning elements within the body while excluding the navbar from being centered

On my webpage, I have a navigation bar and a lot of content. The code structure looks something like this: .container { display: flex; justify-content: center; align-items: center; } <div class="navbar"> <!-- Various links for navigation ...

What is the correct way to display single line code snippets in Firefox?

When attempting to display a single line of code within a code block, the layout appears too close to the line numbers (this issue only occurs in Firefox): The HTML code responsible for this display is automatically generated by Hugo and appears as follow ...

A situation where the event onclick fails to occur within NextJS

index.js: function Home () { return <div> <html> <head> <title>Site</title> </head> <body> <div class= 'v5_3' onclick = "func_click()"></div> </b ...

How to apply custom styling to a specific element within an Angular Material 2 component using CSS based on its Id or

My EntryComponent features a material button menu where I attempted to customize the default style using ::ng-deep. However, the changes affected all button components in the parent Component as well. <style> ::ng-deep .mat-button{ max-width: 50 ...

Customize the color of the active button in Bootstrap Vue

I'm currently utilizing bootstrap in conjunction with Vue.js. My form-checkbox-group setup looks like this <b-form-group label="Select flow" v-slot="{ ariaDescribedby }"> <b-form-checkbox-group v-m ...

The font sizes appear larger when styled with HTML compared to using Photoshop

When I view my <nav> element in Chrome, the font size of each list element appears much larger than it was originally designed in Photoshop. The font is displaying 23px wider in Chrome compared to Photoshop, even though my resolution is set at 72dpi ...

Tips on rearranging the location of a div element within a directive

I have created a custom directive that displays two divs, Div1 and Div2, with a splitter in the middle: Splitter Image Now, I am looking for a way to swap the positions of these two divs dynamically using an Angular directive. I thought about using ng-swi ...

How can I retrieve the locale for dateTimeLocalization in Vue i18n?

Currently, I am using a tutorial on implementing i18n in my vue code. It is working well with just one inconvenience - the language is hard-coded. Here is how my Localization file looks: export default: { 'fr-fr': { ... }, &ap ...

I incorporated a YouTube video using the iframe tag, but encountered an issue where the page would not scroll up or down when the mouse cursor was positioned on the iframe

How would you like your HTML code to function? When the cursor is on the iframe, do you want it to play a video? Also, should the parent page scroll when you scroll? <section class="section section-padding"> <div class="container"> ...

The Google font feature is causing an issue where text cannot be selected when trying to print a

I am in the process of creating a Vue application to generate my CV in PDF format. I have incorporated the Google font Montserrat into the project, but when I attempt to print the page to file (CTRL + P in Firefox), the text appears as if it were an image ...

Changing Parameters in Absolutely Positioned Sections

I have successfully created a fixed header with a higher z-index than the body content, allowing the content to slide underneath it. To position the content div directly below the fixed header, I applied a position:relative and specified a top value. Init ...

What are some ways to decrease the dimensions of my dateTimePicker?

I'm looking to decrease the dimensions of my datetime picker box. Here's an image of my current dateTimePicker: https://i.stack.imgur.com/MeJlq.png Below is the component I'm using: import React, { useState } from 'react'; import ...

Page not reaching the very top when scrolled

Having a puzzling issue that's got me stumped. Currently working on my professor's website at jurgec.net. The problem is specific to the mobile version of the site. Whenever clicking on a link like "I am an undergraduate student," scrolling down ...