layout布局导航菜单

12 篇文章 0 订阅
10 篇文章 0 订阅
import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'
Vue.use(Router)
export default new Router({
  routes: [
    {
      path: '/',
      component: Layout,
      redirect: '/test',
      children: [
        {
          path: 'test',
          name: 'test',
          component: () => import('@/view/test'),
          meta: { title: '首页', icon: 'home' }
        }
      ]
    },

    {
      path: '/s',
      component: Layout,
      redirect: '/s/map',
      meta: { title: '其他', icon: 'home' },
      children: [
        {
          path: 'map',
          name: 'map',
          component: () => import('@/components/map'),
          meta: { title: '地图', icon: 'home' },
        },
        {
          path: 'gojs',
          name: 'gojs',
          component: () => import('@/view/gojs'),
          meta: { title: 'go', icon: 'home' },
        },
      ]
    },
    {
      path: '/home',
      component: Layout,
      redirect: '/home/homes',
      children:[
        {
          path:'homes',
          name:'homes',
          component: () => import('@/view/home'),
          meta: { title: '图表', icon: 'home' }
        }
      ]
    },
  ],
  mode: "history"    //去掉/#/
})

 

children 里面的path 应该要加上父级的路径 ,这里没加 后面统一拼上了

Menu组件

<template>
  <Menu theme="dark" accordion width='220px'>
    <Item v-for="route in routes" :key="route.path" :item="route"></Item>
  </Menu>
</template>
<script>
import Item from './item.vue'
export default {
  name: 'm',
  components:{
    Item
  },
  computed: {
    routes() {
      return this.$router.options.routes
    },
  },
  created() {
    console.log('menu',this.$router.options.routes)
  },
  methods: {

  }
}
</script>

<style scoped>
</style>

Item组件

<template>
  <div>
    <MenuItem v-if="hasOneChild(item)" :to="item.path" :name="item.path">
      <Icon type="ios-paper" /><span>{{item.children[0].meta.title}}</span>
    </MenuItem>
    <template v-else>
        <Submenu :name="item.path">
          <template slot="title">
            <Icon type="ios-apps" /><span>{{item.meta.title}}</span>
          </template>  
          <MenuItem  v-for="items in item.children" :key="items.path" :to="resolvePath(item.path,items.path)" :name="resolvePath(item.path,items.path)">
            <Icon type="ios-paper" /><span>{{items.meta.title}}</span>
          </MenuItem>
        </Submenu> 
    </template>

  </div>

</template>
<script>
import path from 'path'
export default {
  name: 'item',
  computed: {

  },
  props:{
    item:{
      type:Object,
      required:true
    }
  },

  created() {
    console.log('item',this.item)
  },
  methods: {
    // 如果children 里面只有一个 就按照单个显示  如果里面有1个以上就按组折叠显示
    hasOneChild(item){
      if(item.children && item.children.length==1){
        return true
      }else{
        return false
      }
    },
    // chilidren 里面的路径 拼上父级路径
    resolvePath(base,routePath){
       return path.resolve(base, routePath)
    }
  }
}
</script>

<style scoped>
</style>

Vue-Admin 的 Layout 布局主要是通过 Vue.js 和 Element UI 组件库来实现的。 首先,可以使用 Element UI 的布局组件来实现整体页面的布局,常用的有 Container、Header、Aside、Main 和 Footer 等组件。 例如,可以在 App.vue 中使用 Container 组件来包裹整个页面,并在其中放置 Header、Aside 和 Main 组件: ```html <template> <div id="app"> <el-container> <el-header>Header</el-header> <el-container> <el-aside>Aside</el-aside> <el-main>Main</el-main> </el-container> </el-container> </div> </template> ``` 然后,可以在 Main 组件中使用 Router-View 组件来实现路由页面的动态渲染,同时可以在 Aside 组件中使用菜单组件来实现导航菜单的展示。 除了使用 Element UI 组件外,还可以在 Layout 组件中封装一些公共的功能,例如面包屑导航、全局 Loading 状态等,方便在多个页面中复用。同时,也可以使用 Vuex 状态管理库来管理全局状态,例如用户登录状态、菜单权限等。 最后,如果需要实现响应式布局,可以使用 Element UI 的断点样式和栅格系统来实现。例如,在 Main 组件中使用 Row 和 Col 组件来实现列表页面的布局: ```html <template> <el-main> <el-row :gutter="20"> <el-col :xs="24" :sm="12" :md="8" :lg="6" v-for="item in list" :key="item.id"> <div class="item">{{ item.title }}</div> </el-col> </el-row> </el-main> </template> ``` 以上就是 Vue-Admin 的 Layout 布局实现的基本方法,可以根据具体的需求进行扩展和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值