layout-------------模板包含菜单栏等主要框架
router--------------路由管理,根据路由可生成左侧菜单栏

/** When your routing table is too long, you can split it into small modules**/import Layout from '@/layout'var search = [{path: '/supervise/report',component: Layout,name: 'report',meta: { title: '**', icon: 'component' },children: [{path: 'reportCQL',component: () => import('@/views/supervise/report/reportCQL'),name: 'reportCQL',meta: { title: '**', icon: 'icon' }}------]},{path: '/supervise/search',component: Layout,name: 'search',meta: { title: '**', icon: 'component' },children: [{path: 'forestQuery',component: () => import('@/views/supervise/search/forestQuery'),name: 'forestQuery',meta: { title: '**', icon: 'search' }}]}
]
export default {getMenuMessage:function () {return search;}
}

这是一简单路由,具体见https://panjiachen.github.io/vue-element-admin-site/zh/guide/essentials/router-and-nav.html详解
views哈视图s-主要存放.vue也就是具体的页面,多级菜单路由生成

index.vue代码如下

{path: '/nested',component: Layout,redirect: '/nested/menu1',name: 'Nested',meta: {title: '**',icon: 'nested'},children: [{path: 'menu1',component: () => import('@/views/nested/menu1/index'), // Parent router-viewname: 'Menu1',meta: { title: '**' },children: [{path: 'houselist',component: () => import('@/views/house/houselist'),name: 'houselist',meta: { title: '**' },children: [。。。。。此处省略

然后回来看layout文件下
index.vue引入

import { Topbar, Navbar, Sidebar, AppMain } from “./components”;

components: {
Topbar,
Navbar,
Sidebar,
AppMain
},

export { default as Topbar } from './Topbar'
export { default as Navbar } from './Navbar'
export { default as Sidebar } from './Sidebar'
export { default as AppMain } from './AppMain'

components下sidebar文件就是左侧菜单了
TopBar是我们的顶部菜单

<template><div><el-menu:default-active="activeIndex"class="topbar-menu"mode="horizontal"@select="handleSelect"background-color="#3a3a3a"text-color="#bfcbd9"active-text-color="#e7ae12"><a href="/"><img :src="logo" class="topbar-logo" :class="aWidth" /></a><div class="title" v-if="sidebar.opened">{{name}}</div><el-menu-item index="0"><a href="/" @click="toggle('0')">首页</a></el-menu-item><el-dropdown class="company-menu"  style="margin-right:20px"  @command="handleCommand"><span class="el-dropdown-link">{{myCompany}}<i class="el-icon-arrow-down el-icon--right"></i></span><el-dropdown-menu slot="dropdown"><el-dropdown-item command="e">企业设置</el-dropdown-item><el-dropdown-item command="e">切换企业</el-dropdown-item><el-dropdown-item command="e" divided> 添加企业成员</el-dropdown-item></el-dropdown-menu></el-dropdown><div class="right-menu"><el-dropdown class="avatar-container" trigger="click"><div class="avatar-wrapper"><img :src="avatar+'?imageView2/1/w/80/h/80'" class="user-avatar" /><i class="el-icon-caret-bottom" /></div><el-dropdown-menu slot="dropdown" class="user-dropdown"><router-link to="/user/userInfo"><el-dropdown-item><a href="/#/user/userInfo">基本信息</a></el-dropdown-item></router-link><router-link to="/user/SafetyManagement"><el-dropdown-item><a href="/#/user/SafetyManagement">安全管理</a></el-dropdown-item></router-link><el-dropdown-item divided><span style="display:block;" @click="logout">退出登录</span></el-dropdown-item></el-dropdown-menu></el-dropdown></div></el-menu></div>
</template>

然后怎么点击顶部菜单左侧菜单也变化-模块
首先要把router路由拆分开
在layout-components-Sidebar文件下index.vue改变菜单参数也就是将router的各个模块分别读取出来

到这里应该了解一下vuex的mapGetters
参考mapGetters
还有$store.dispatch
dispatch

routes()返回的是菜单的参数,根据不同标识返回不同菜单,当然也可以将菜单存到后台,通过异步请求得到菜单

在顶部菜单Topbar中添加事件

store文件中,我添加到app中

import Cookies from 'js-cookie'
const state = {menuIndex: {opened: Cookies.get('menuIndexStatus') ? Cookies.get('menuIndexStatus') : '0',withoutAnimation: false}
}
const mutations = {TOGGLE_MENU: (state, device) => {console.log(device)state.menuIndex.opened = devicestate.menuIndex.withoutAnimation = falseCookies.set('menuIndexStatus', device)}
}const actions = {toggleMenu({ commit }, device) {commit('TOGGLE_MENU', device)}
}
export default {namespaced: true,state,mutations,actions
}
当点击菜单时会改变menuIndex.opened
左菜单添加
import { mapGetters } from "vuex";
......
computed: {...mapGetters([ 'menuIndex']),
........```有点啰嗦,这里遇到了一个问题,不知道是我这里的问题,还是本身就会出现,当放大缩小浏览器会报
TypeError: Cannot create property 'opened' on string 'desktop'"
没有找到根本原因

vue-cli 添加顶部导航栏及点击导航菜单,左侧菜单栏切换相关推荐

  1. 微信小程序实现自定义顶部导航栏(选项卡),固定导航栏和可滑动导航栏

    微信小程序实现自定义顶部导航栏(选项卡),固定导航栏和可滑动导航栏 固定导航栏 可滑动导航栏 顶部导航栏的需求实现: 顶部导航栏由列表渲染,通过tabclick点击事件改变activeIndex变量的 ...

  2. 【Flutter】底部导航栏实现 ( BottomNavigationBar 底部导航栏 | BottomNavigationBarItem 导航栏条目 | PageView )

    文章目录 一.Scaffold 组件 二.底部导航栏整体架构 三.BottomNavigationBar 底部导航栏 四.BottomNavigationBarItem 导航栏条目 五.PageVie ...

  3. 微信小程序入门四: 导航栏样式、tabBar导航栏

    实例内容 导航栏样式设置 tabBar导航栏 实例一:导航栏样式设置 小程序的导航栏样式在app.json中定义. 这里设置导航,背景黑色,文字白色,文字内容测试小程序 app.json内容: {&q ...

  4. css导航栏_CSS:创建导航栏

    css导航栏 Every website needs a navgation bar to help visitors navigate around the website. This is gen ...

  5. css基础 CSS 导航栏、CSS 下拉菜单

    阅读目录 导航栏 导航栏=链接列表 垂直导航栏 垂直导航条实例 激活/当前导航条实例 创建链接并添加边框 全屏高度的固定导航条 水平导航栏 内联列表项 浮动列表项 水平导航条实例 链接右对齐 添加分割 ...

  6. powerbuilder 做业务导航图_教你学CAD导航栏,掌握通用导航工具和产品特定的导航工具也重要...

    阅读完,如果觉得有用,那么点击"关注"和点赞是对作者的一种尊重和鼓励.版权所有,抄袭必究.作者的新书<AutoCAD 2020中文版入门-进阶-精通(第6版)>已经正式 ...

  7. Boostrap_响应式导航栏,点击汉堡按钮遮盖下方元素

    Boostrap_响应式导航栏,点击汉堡按钮遮盖下方元素 官网那个是直接把其他元素挤到下面了 根据这个大哥的源码改了改:https://blog.csdn.net/mazhili1991/articl ...

  8. iOS小技能:自定义导航栏,设置全局导航条外观。(iOS15适配)

    文章目录 前言 I 自定义导航栏 1.1 自定义导航条 1.2 设置全局导航条按钮主题 1.3 设置导航条渐变颜色 1.4 ` 拦截push` II 相关代码 see also 前言 需求:同一个模块 ...

  9. 还原淘宝首页最顶部的导航栏(含下拉菜单,图标等)

    还原了淘宝首页最顶部的导航栏,包括了各个导航的下拉列表等(位置对齐稍微有些偏差,毕竟没有原版设计图),用到了jquery,js,CSS3等知识.没有花时间去做录屏GIF,就几张效果图看下:如下 原始导 ...

最新文章

  1. 使用autoconf完成编译配置
  2. 随机产生长度为20的字符串(数字和大小写字母)
  3. c语言修改elf文件crc32,ELF文件中调试信息的格式说明?
  4. Difference: throw or throw ex?
  5. python面向对象语言_Python语言基础之——面向对象编程
  6. php模板技术 实例
  7. 【Xamarin挖墙脚系列:关闭 OS X El Capitan 中 SIP 安全设置功能】
  8. 【CF913G】Power Substring 数论+原根
  9. 用Redis实现Session功能
  10. kitti数据集坐标转换
  11. python 使用 config 文件
  12. js 直接打开选择文件窗口_打开CAD文件时,怎么快速选择“gbcbig.shx”字体?
  13. Zabbix企业微信告警最新版
  14. 2023.02.07草图大师SU模型渲染- 效果图之加深颜色的色调
  15. Solidity 基础(一)
  16. DIV+CSS 鼠标样式,鼠标手型样式
  17. 一篇就够,线程与线程池的那些事之线程池篇
  18. python设计一个节假日字典_python实现在无须过多援引的情况下创建字典的方法
  19. c语言中 在对全部数组元素赋初值时,在对数组全部元素赋初值时,不可以省略行数,但能省略列数...
  20. 树莓派3B--控制继电器

热门文章

  1. 高校学生信息管理系统
  2. docker的常用基本命令
  3. 【安装配置Git】最新版Git安装教程
  4. 关于jason中大括号和中括号的区别
  5. 如何运行vue项目(详细步骤)
  6. [附源码]Python计算机毕业设计SSM基于框架的报修系统(程序+LW)
  7. 【Oracle】SCOTT用户和HR用户
  8. Spark word2vec使用
  9. 牧牛图-南怀瑾上师讲解
  10. 爱 —— 哥林多前书(1 Corinthians)第13章