相思资源网 Design By www.200059.com

本文实例为大家分享了vue侧边栏导航的具体代码,供大家参考,具体内容如下

最终效果

vue实现侧边栏导航效果

vue实现侧边栏导航效果

点击下一个导航,上一个导航自动收回

vue实现侧边栏导航效果

实现代码

1.下载vue-router

npm install vue-router --save-dev

2.在main.js中引入

import Vue from 'vue'
import Router from 'vue-router' 
Vue.use(Router) // 引入路由

3.在components中新建组件

3.1 agencySearch.vue组件

代码:

<template>
 <div>
  直属下线代理查询
 </div>
</template>

3.2 agencySet.vue组件

代码

<template>
 <div>
  直属下线代理设置
 </div>
</template>

3.3 financialIncome.vue组件

代码

<template>
 <div>
  财务收益数据报表
 </div>
</template>

4.在router下的index.js中引入组件,搭配路由

//4.1引入组件
import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/Home' // 主页
import agencySearch from '@/components/agencySearch' // 直属下线代理查询
import agencySet from '@/components/agencySet' // 直属下线代理设置
Vue.use(Router)
//搭配路由
export default new Router({
 mode: 'history',
 scrollBehavior: () => ({
 y: 0
 }),
 routes: [
 {
  // 主页
  path: '/',
  component: Home,
  name: '代理事物',
  iconCls: 'el-icon-message',
  children: [{
  path: '/agencySearch',
  component: agencySearch,
  name: '直属下线代理查询',
  hidden: true
  },
  {
  path: '/agencySet',
  component: agencySet,
  name: '直属下线代理设置'
  }]
 },
 {
  // 主页
  path: '/',
  component: Home,
  name: '财务报表',
  iconCls: 'el-icon-menu',
  children: [{
  path: '/financialIncome',
  component: financialIncome,
  name: '财务收益数据报表',
  hidden: true
  }]
 }]
})

5.在主页Home组件中搭配导航以及路由出口

在el-menu标签中一定要有 unique-opened 和 router属性,在el-menu-item中index属性值等于在router下index.js中配好的路由名字

这个是从element官网截取的

vue实现侧边栏导航效果

vue实现侧边栏导航效果

<el-row class="tac">
 <el-col :span="24">
 <el-menu
  default-active="1"
  class="el-menu-vertical-demo"
  unique-opened 
  router>
  <el-submenu index="1">
  <template slot="title">
   <i class="el-icon-message"></i>
   <span>代理事务</span>
  </template>
  <el-menu-item-group>
  <template slot="title"></template>
  <el-menu-item index="/agencySearch">直属下线代理查询</el-menu-item>
  <el-menu-item index="/agencySet">直属下线代理设置</el-menu-item>
  </el-menu-item-group>
  </el-submenu>
  <el-submenu index="2">
  <template slot="title">
   <i class="el-icon-menu"></i>
   <span>财务报表</span>
  </template>
  <el-menu-item-group>
  <template slot="title"></template>
  <el-menu-item index="/financialIncome">财务收益数据报表</el-menu-item>
  </el-menu-item-group>
  </el-submenu>
 </el-menu>
 </el-col>
</el-row>

路由出口-右侧显示部分

<el-col :span="24" class="content-wrapper">
 <transition name="fade" mode="out-in">
  <router-view></router-view>
 </transition>
 </el-col>

结语:因为是从写好的代码中截取的一部分,可能跑不起来,请见谅,我能理解的原理部分都写在这里啦。

更多教程点击《Vue.js前端组件学习教程》,欢迎大家学习阅读。

关于vue.js组件的教程,请大家点击专题vue.js组件学习教程进行学习。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

标签:
vue,侧边栏,导航

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“vue实现侧边栏导航效果”

暂无vue实现侧边栏导航效果的评论...

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。