I am using Vue.js for my project and I have made a dashboard section but I want something that is responsive and should use bootstrap or bootstrap-vue or plain HTML, CSS. Attaching the pictures of the dashboard I want to have ->
This is the post I am following vuebootstrap b-collapse: when sidebar collapse, change margin-left content div
My code---
<div>
<b-collapse v-model="visible" id="collapse-4">
<div class="sidebar scrollable-menu">
<div style="height: 36%">
<img
src="../../../public/images/profile.png"
style="
width: 70px;
height: 70px;
border-radius: 50%;
margin-top: 40px;
"
/>
<h3
style="
font-weight: bold;
font-size: 16px;
margin-top: 15px;
color: white;
"
>
Hello {{name}}
</h3>
<button
class="mr-2 mt-2 btn"
style="
background-color: #595cf5;
color: white;
border-radius: 20px;
font-size: 12px;
padding: 3px 8px;
"
>
<b-link
:to="{ path: '/dashboard/freelancer/editprofile' }"
style="background-color: #595cf5; color: white"
>Edit profile</b-link
>
</button>
</div>
<div style="background-color: #3b4664; height: 65%">
<ul class="ul-dash">
<li>
<b-link
exact-active-class="active"
:to="{ path: '/dashboard/freelancer/' }"
>
<b-icon icon="pentagon" class="mr-4"></b-icon>Home</b-link
>
</li>
<li>
<b-link
exact-active-class="active"
:to="{ path: '/dashboard/freelancer/projects' }"
><b-icon icon="files" class="mr-4"></b-icon>Projects</b-link
>
</li>
<li>
<b-link
exact-active-class="active"
:to="{ path: '/dashboard/freelancer/invitations' }"
>
<b-icon icon="person-plus" class="mr-4"></b-icon
>Invitations</b-link
>
</li>
<li>
<b-link
exact-active-class="active"
:to="{ path: '/dashboard/freelancer/transactions' }"
><b-icon icon="cash" class="mr-4"></b-icon>Transactions</b-link
>
</li>
<li>
<b-link
exact-active-class="active"
:to="{ path: '/dashboard/freelancer/referrals' }"
><b-icon icon="people-fill" class="mr-4"></b-icon>Referrals</b-link
>
</li>
<li>
<b-link
exact-active-class="active"
:to="{ path: '/dashboard/freelancer/resume' }"
>
<b-icon icon="file-earmark-text" class="mr-4"></b-icon
>Resume</b-link
>
</li>
</ul>
<div class="contact">
<span style="color: gray"> Having troubles? </span>
<p>Contact us</p>
</div>
</div>
</div>
</b-collapse>
<div class="content">
<b-navbar fixed="top" class="navbar">
<b-navbar-brand href="#"
><img
src="../../../public/images/fevicon.png"
:class="visible ? null : 'collapsed'"
:aria-expanded="visible ? 'true' : 'false'"
aria-controls="collapse-4"
@click="visible = !visible"
style="
width: 30px;
margin-right: 10px;
box-shadow: 1px 1px 3px #eaeaea;
border-radius: 50%;
"
/>KickStartup
</b-navbar-brand>
<b-collapse id="nav-collapse" is-nav>
<!-- Right aligned nav items -->
<b-navbar-nav class="ml-auto">
<!-- <b-nav-item href="#" class="nav-item"
><span>Top 1%</span></b-nav-item
> -->
<b-nav-item-dropdown right>
<!-- Using 'button-content' slot -->
<template #button-content>
<img
src="../../../public/images/profile.png"
style="width: 25px"
/>
</template>
<b-dropdown-item to="/dashboard/freelancer/editprofile"
>Profile</b-dropdown-item
>
<b-dropdown-item @click="logout">Sign Out</b-dropdown-item>
</b-nav-item-dropdown>
</b-navbar-nav>
</b-collapse>
</b-navbar>
<div class="maincontent">
<router-view></router-view>
</div>
</div>
CSS -
.sidebar {
position: fixed;
background-color: #181e36;
border-radius: 0px;
top: 0px;
left: 0px;
height: 100vh;
width: 270px;
z-index: 1000;
overflow-x: hidden;
overflow-y: auto;
padding-left: 0;
padding-right: 0;
}
.nav-item span {
background-color: orange;
padding: 5px 10px;
border-radius: 10px;
color: white;
margin-right: 10px;
}
.navbar {
margin-left: 0px;
background-color: white !important;
box-shadow: 0px 2px 5px 2px #efefef, 0px 2px 5px 2px #efefef;
}
.collapse.show ~ .content {
margin-left: 280px;
}
.collapse.show ~ .content .navbar {
margin-left: 272px;
}
.content {
margin-top: 0px;
margin-right: 5px;
border-radius: 15px;
}
.maincontent {
margin-top: 60px;
}
.active {
color: white !important;
}
.ul-dash li a {
color: #aeb1ba;
}
.ul-dash {
position: relative;
padding-top: 20px;
margin: -10px;
color: lightgray;
}
.ul-dash li {
text-align: start;
display: block;
list-style: none;
font-size: 17px;
margin-bottom: 20px;
}
a:hover {
text-decoration: none;
}
.ul-dash .active::after {
content: "• "; /*don't miss the space*/
color: #595cf5;
font-size: 20px;
margin-left: 45px;
}
.contact {
margin: 20px;
margin-top: 90px;
text-align: start;
background-color: #181e36;
border-radius: 15px;
color: white;
font-size: 13px;
padding-top: 10px;
}
.contact p {
margin: 0px 15px;
padding: 5px 0 10px 0;
}
.contact span {
margin-left: 15px;
}
js -
props: {},
created() {
HTTP.get("/freelancerdash/myprofile", {
withCredentials: true,
})
.then((res) => {
console.log(res);
this.name = res.data.name;
})
.catch((errors) => {
console.log("error hai");
});
},
data() {
return {
visible: true,
name: "",
};
},
methods: {
...mapActions(["logout"]),
},
bind the <b-collapse>
with a v-model
is a misunderstanding of the v-model
directive. the v-model
directive is used to bind form elements, instead to show/hide elements you need to use v-if
or v-show
, here you can learn the difference directive. you can see here the documentation for deep understanding of v-model directive.
for your purpose, allow the bootsrap-vue documentation, instead of using the <b-collapse>
component you can try with the <b-sidebar>
component
<template>
<div>
<b-button v-b-toggle.sidebar-right>Toggle Sidebar</b-button>
<b-sidebar id="sidebar-right" title="Sidebar" right shadow>
<div class="px-3 py-2">
<p>
Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis
in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.
</p>
<b-img src="https://picsum.photos/500/500/?image=54" fluid thumbnail></b-img>
</div>
</b-sidebar>
</div>
</template>
i think this will work like you want.
Other solution:
there is vuetify, that is a material Vue UI Library, and precisely here there is a component that works like what you asked for.
/components/Menu/Burger.vue
<template>
<div id="burger" :class="{ 'active' : isBurgerActive }" @click.prevent="toggle">
<slot>
<div class="container-fluid">
<div class="row">
<button type="button" class="burger-button" title="Menu">
<span class="hidden">Toggle menu</span>
<span class="burger-bar burger-bar--1"></span>
<span class="burger-bar burger-bar--2"></span>
<span class="burger-bar burger-bar--3"></span>
</button>
</div>
</div>
</slot>
</div>
</template>
<script>
import { store, mutations } from '@/store';
export default {
computed: {
isBurgerActive() {
return store.isNavOpen;
}
},
methods: {
toggle() {
mutations.toggleNav();
}
}
};
</script>
<style>
.hidden {
visibility: hidden;
}
button {
cursor: pointer;
}
/* remove blue outline */
button:focus {
outline: 0;
}
.burger-button {
position: relative;
height: 45px;
width: 45px;
display: block;
z-index: 999;
border: 2px solid #F56905;
border-radius: 10px;
background-color: transparent;
pointer-events: all;
transition: transform 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
}
.burger-bar {
background-color: #8cae42;
position: absolute;
top: 50%;
right: 6px;
left: 6px;
height: 3px;
width: auto;
margin-top: -1px;
transition: transform 0.6s cubic-bezier(0.165, 0.84, 0.44, 1),
opacity 0.3s cubic-bezier(0.165, 0.84, 0.44, 1),
background-color 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
}
.burger-bar--1 {
-webkit-transform: translateY(-6px);
transform: translateY(-6px);
}
.burger-bar--2 {
transform-origin: 100% 50%;
/*transform: scaleX(0.8);*/
}
.burger-button:hover .burger-bar--2 {
transform: scaleX(1);
}
.no-touchevents .burger-bar--2:hover {
transform: scaleX(1);
}
.burger-bar--3 {
transform: translateY(6px);
}
#burger.active .burger-button {
transform: rotate(-180deg);
}
#burger.active .burger-bar {
background-color: #fff;
}
#burger.active .burger-bar--1 {
transform: rotate(45deg);
}
#burger.active .burger-bar--2 {
opacity: 0;
}
#burger.active .burger-bar--3 {
transform: rotate(-45deg);
}
.menutext{
margin-bottom: 0;
line-height: 1;
vertical-align: center;
font-weight: bold;
padding-left: 5%;
padding-top: 5%;
font-size: .9em;
margin-top: auto;
margin-bottom: auto;
}
</style>
/components/Menu/Sidebar.vue
<template>
<div class="sidebar">
<div class="sidebar-backdrop" @click="closeSidebarPanel" v-if="isPanelOpen"></div>
<transition name="slide">
<div v-if="isPanelOpen"
class="sidebar-panel">
<slot></slot>
</div>
</transition>
</div>
</template>
<script>
import { store, mutations } from '@/store';
export default {
methods: {
closeSidebarPanel: mutations.toggleNav
},
computed: {
isPanelOpen() {
return store.isNavOpen
}
},
watch: {
'$route' () {
if(store.isNavOpen){
this.closeSidebarPanel();
}
}
}
}
</script>
<style>
.slide-enter-active,
.slide-leave-active
{
transition: transform 0.2s ease;
}
.slide-enter,
.slide-leave-to {
transform: translateX(-100%);
transition: all 150ms ease-in 0s
}
.sidebar-backdrop {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
cursor: pointer;
z-index: 1000;
}
.sidebar-panel {
overflow-y: auto;
position: fixed;
left: 0;
top: 0;
height: 100%;
z-index: 999;
padding: 3rem 20px 2rem 20px;
width: 300px;
z-index: 1001;
}
</style>
/components/Navigation.vue
<template>
<div class="container-fluid">
<div class="row">
<div class="col-lg-4 col-md-12">
<nav class="main-nav">
<Burger></Burger>
<Sidebar>
<ul class="sidebar-panel-nav">
<li>
<router-link to="/">Home</router-link>
</li>
<li>
<router-link to="/about">About</router-link>
</li>
<li>
<router-link to="/contact">Contact Us</router-link>
</li>
</ul>
</Sidebar>
</nav>
</div>
<div class="col-lg-4 col-md-12">
<h1>Hardik Rawat</h1>
</div>
</div>
</div>
</template>
<script>
import Burger from "@/components/Menu/Burger.vue";
import Sidebar from "@/components/Menu/Sidebar.vue";
export default {
name: "Navigation",
components: {
Burger,
Sidebar
},
methods: {
navHome() {
this.$router.push({ name: 'Home' });
},
}
}
</script>
<style>
.main-nav {
display: flex;
justify-content: space-between;
padding: 0.5rem 0.8rem;
}
ul.sidebar-panel-nav {
list-style-type: none;
}
ul.sidebar-panel-nav > li > a {
color: #fff;
text-decoration: none;
font-size: 1.5rem;
display: block;
padding-bottom: 0.5em;
}
</style>
/App.vue
<template>
<div id="app">
<Navigation></Navigation>
<main>
<router-view></router-view>
</main>
</div>
</template>
<script>
import Navigation from "@/components/Navigation";
import { store, mutations } from '@/store'
components: {
Navigation
},
methods: {
closeSidebarPanel: mutations.toggleNav,
},
computed: {
isPanelOpen() {
return store.isNavOpen
}
}
</script>
/store.js
import Vue from 'vue';
export const store = Vue.observable({
isNavOpen: false,
});
export const mutations = {
setIsNavOpen(yesno) {
store.isNavOpen = yesno;
},
toggleNav() {
store.isNavOpen = !store.isNavOpen;
},
};
I recommend that you use Vuetify and use the Toolbar component. Then you can make this responsive using display helpers.
Inside the <v-toolbar> tag, we can use the following code:
this will display when screen is medium or greater
<div class="d-none d-md-block">
<v-btn outlined @click="$router.push('/login')">
<span>
Login
</span>
</v-btn>
</div>
this will display when screen is smaller than medium
<div class="d-md-none">
<v-btn icon @click.stop="drawer = !drawer">
<v-app-bar-nav-icon></v-app-bar-nav-icon>
</v-btn>
</div>
This is the code for navigation drawer
<v-navigation-drawer
v-model="drawer"
absolute
temporary
right
>
<v-list-item>
<v-list-item-content>
<v-list-item-title>MENU</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-divider></v-divider>
<v-list dense>
<v-list-item
v-for="item in items"
:key="item.title"
:href="item.title"
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>
</v-navigation-drawer>
where item.title and item.icon is returned by the data() function in your script
Links:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.