navtop -sidebar -menubar 组合思路

本文介绍Vue.js项目中路由配置及组件管理的方法,包括主页面布局、侧边栏导航、多级路由设置等关键技术实现。
  • app.vue 为主页面
  • 通过路由 定位到 首页 8080/home/index
  • 路由一级要记得写 component: Layout
  • 可以在 <router-view .> 里面写class 从而置顶样式
    路由代碼
import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/views/layout/index.vue'
import { publish } from "@/views/publish/router"
import { websiteServer } from "@/views/websiteServer/router"
Vue.use(VueRouter)

let routes = [
  {
    path: '/',
    redirect: '/home/index',
    hide: true
  },
  {
    path: '/home',
    name: 'Home',
    meta: { title: '首页', full: true, icon: 'example' },
    isMenubarShow: false,
    component: Layout,
    children: [{
      path: 'index',
      name: 'index1',
      meta: { title: '首页' },
      component: () => import('@/views/home/index.vue'),
    }]
  },
]
routes = routes.concat(publish, websiteServer)  // 合并路由
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router

  • 当路由进到home/index 页面时 会渲染导航栏 component: Layout

再是 layout 页面

<template>
  <div class="app-container">
    <sidebar />
    <div class="container">
      <navtop />
      <div class="main">
        <!-- 当路由 meta: {Full:false }为fasle  不展示二级路由 不让展示-->
        <menubar v-show="!menubarFull" />
        <!-- 展示主页面 -->
        <router-view class="main-content"/>
      </div>
    </div>
  </div>
</template>
<script>
computed: {
    menubarFull() {  // 判断二级是不是需要隐藏不渲染
      return this.$store.state.menubar.meta.full
    },
  },
  watch: {},
  mounted() {
    const routes = this.$router.options.routes // 所有路由
    const currentRouter = this.$route.path // 当前活跃的路由
    const item = routes.find(x => x.path !=='/' && currentRouter.indexOf(x.path) > -1)
    if (item) {
      this.$store.commit('CHANGEMENU', item)
    }
    this.$store.dispatch('listGeologyTree') // 省市区
    this.$store.dispatch('listRoleName') // 角色展示
<script>
  },
+ 侧边栏  数据信息从 路由里面获取 this.$router.options.routes 
+ defaultRouter 默认的当前一级路由   this.$route.path
+ <el-menu.> router 路由形式菜单
+ routers 为所有路由信息   this.$router.options.routes
+ <el-menu-item.> index 为待选中路由的标识
+ :route="{path: item.path + '/' + item.children[0].path}" 路由形式跳转
+ 点击一
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值