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

What is the most effective way to reset the v-model in the child component using the parent component?

Could you please assist me? I have been trying for 10 hours straight and it doesn't seem to work. What I am aiming for is that when I click on @click="cleanDataForm" in the Parent Component, the v-model text in the Child component will be emptied. I h ...

The appearance of a CSS select box may vary across different computers and web browsers

The appearance of a select box in HTML can vary between different computers and browsers. For example, on one computer using Google Chrome, the select box may look like this: https://i.stack.imgur.com/g2Xnn.png However, on my computer with Google Chrome, ...

Other elements are unable to conceal Material UI InputBase

Displayed below is a navigation bar that sticks to the top, followed by rows of InputBase components from material-ui. Despite setting the background color of the nav bar to white, the input always appears above the nav. This strange behavior stopped when ...

What are some techniques for ensuring a CSS div remains stable and intact when adjusting the browser size?

Is there a way to prevent the entire website from resizing when you minimize or maximize your browser? I want the website size to adjust in proportion to your resize without reorganizing everything. How can this be achieved while maintaining the site lengt ...

What is the best way to wrap all divs except for the one with a .header-container-wrapper class?

In the midst of a project involving hubspot, I am facing an issue. I need to enclose all div elements within the body tag, except those with the class .header-container-wrapper. The default code provided by hubspot wraps all divs within #site-wrapper. $(& ...

What could be causing my Material UI Table to disappear when I toggle the "Show" option?

I am incorporating the Grow material ui component to display or hide a table. Initially, the table is visible. <Box className={classes.object_controls_wrapper}> <Box sx={{ display: "flex" }}> <Grow in={objectViewOpened ...

Vue: Conditionally importing SCSS when a component is instantiated

My goal is to import Material SCSS exclusively for my Admin component. While this setup works smoothly during local development, the issue arises when I deploy my site to Firebase hosting - the Material styles start affecting not just my Admin component, ...

Attempting to eliminate the vertical scroll on my page that matches the height of the navigation bar

I am struggling with the alignment of a login page form that needs to be centered both horizontally and vertically, while allowing for slight scrolling down to accommodate the navigation bar height. I have attempted to adjust the classes and style height ...

Is there a way to retrieve a compilation of custom directives that have been implemented on the Vue 3 component?

Is there a way to retrieve the list of custom directives applied to a component? When using the getCurrentInstance method, the directives property is null for the current component. I was expecting to see 'highlight' listed. How can I access the ...

The difference in percentage padding rendering is specific to Firefox only

In my current project, I have created various responsive boxes for displaying news articles on the website. Everything seems to be functioning well except for the news items within the slider at the top of the main content. Surprisingly, they are displayin ...

How to create a dynamic background color animation in jQuery similar to a progress bar animation

I have a container with text content (for example: My Name) and it is displayed in a RED background color along with a button. What I am looking for : When the button is clicked, I want to change the background color of the container from RED to BLUE, si ...

Using Slick Slider and Bootstrap CSS to display text on top of images

Currently, I am utilizing the slick slider from and I want to overlay text on top of the image. I tried using bootstrap carousel-caption, which works well with any image. However, with slick slider, it seems like the text is not at the highest level as I ...

What is the best way to rearrange images within a grid container?

I apologize for asking numerous questions, but could someone please guide me on how to position an image slightly to the right of center or just 1 inch to the left of center? http://jsfiddle.net/96d7udd7/ Below is the HTML code snippet: <figure class ...

Prevent clicks from passing through the transparent header-div onto bootstrap buttons

I have a webpage built with AngularJS and Bootstrap. It's currently in beta and available online in (German and): teacher.scool.cool simply click on "test anmelden" navigate to the next page using the menu This webpage features a fixed transparent ...

Having trouble with your website not adjusting properly when resizing the browser or viewing it on a mobile phone

My website is not adapting properly to different screen sizes, even after I have added the META tags below. Any advice would be appreciated. Thank you. HTML <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="UTF-8> ...

Examining the scroll-down feature button

I'm currently experimenting with a scroll down button on my website and I'm perplexed as to why it's not functioning properly. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" c ...

Using the ES5 syntax with ag-Grid Vue

Can ag-grid-vue be used with ES5 without webpack or babel? I encountered the error below: Uncaught ReferenceError: exports is not defined at agGridVue.js:3 Is it possible to use ag-grid-vue with just pure javascript, or does it need a transpiler? ...

Content below divs that are fixed and absolutely positioned

I have a design layout similar to this (a small snippet) and I am facing an issue where the text within .content is not clickable. The positioning of #gradient is fixed due to the background image, and #empty has an absolute position to cover the entire bo ...

Acquiring information from a different Vue.js component

I am faced with a puzzle involving 2 components, A and B. Component A: import B from '../components/B.vue'; export default { components: { B }, methods: { test: function() { console.log(B.data().settin ...

"Enhance your website navigation with the Bootstrap BS3 navbar clc Dropdown-Submenu feature

Utilizing Bootstrap BS3 for the construction of my Django website. I created a dropdown-submenu that is operational on http://www.bootply.com/nZaxpxfiXz# However, when implementing the same in my project, I encountered: The issue is that the dropdown-men ...