首先看最终效果图:

1.compent文件夹里添加tab文件夹,里面创建index.vue index.js index.css

index.vue内的template部份代码如下:(最新更正:代码里所有a标签部份应该用router-link)

<template>
<div>
<!-- 侧导航左栏 -->
<div class="tabNav">
<div style="border: 1px solid rgba(235,236,240,1);margin-left:16px;margin-top: 20px;">
<div v-for="(item,index) in tabList" :key="index" @mouseenter="tabChange(item.children,index)" @mouseleave="tabHide()":class="{active:index==isActive}">
<div class="tabLeft" >
<div class="tabTitle" style="margin-bottom:9px">
<!-- <a class="tabhref" :href="item.url">{{item.name}}</a> -->
<router-link class="tabhref" :to="item.url">{{item.name}}</router-link>
</div>
<div class="tabContent" v-for="item1 in item.children" style="float:left;margin-left:15px">
<!-- <a class="tabLabel" :href="item1.url">{{item1.name}}</a> -->
<router-link class="tabLabel" :to="item1.url">{{item1.name}}</router-link>
</div>
</div>
</div>
</div> </div>
<!-- 侧导航内容 -->
<div class="tabs-content" v-if="tabcontentShow" @mouseenter="tabShow()" @mouseleave="tabHide()">
<div class="tabDetail" v-for="item in this.tabcontent">
<h4 class="tabLabel"><router-link class="tabhref" :to="item.url">{{item.name}}</router-link></h4>
<div style="display:flex;flex-wrap: wrap;justify-content:space-around;padding-top:8px;">
<div class="tabLabelSon" v-for="item1 in item.children">
<!-- <a class="tabhref tabLabelSon" :href="item1.url">{{item1.name}}</a> -->
<router-link class="tabLabel" :to="item1.url">{{item1.name}}</router-link>
</div>
</div>
</div>
</div>
</div> </template> <script>
import axios from '../../plugins/axios.js';
export default {
name:'Tabs',
data() {
return {
tabList:[
// {tabtitle:"店铺管理",tabhref:'www.baidu.com',tablabel:[
// {tablabName:'管理公司信息',tablabHerf:'www.baidu1.com'},
// {tablabName:'V认证',tablabHerf:'www.baidu2.com'},
// {tablabName:'test3',tablabHerf:'www.baidu3.com'}
// ],
// tabcontent:[
// {title:'管理公司信息',href:'www.baidu.com',detail:[
// {detaillab:'管理公司信息',detailhref:'www.baidu1.com'},
// {detaillab:'806',detailhref:'www.baidu2.com'}]},
// {title:'A&V认证',href:'www.baidu.com',detail:[
// {detaillab:'V认证',detailhref:'www.baidu1.com'},
// {detaillab:'8321嗯去为06',detailhref:'www.baidu1.com'},]},
// {title:'新南方',href:'www.baidu.com',detail:[
// {detaillab:'80请问3',detailhref:'www.baidu1.com'},
// {detaillab:'803216',detailhref:'www.baidu1.com'},]},
// {title:'新杯方',href:'www.baidu.com',detail:[
// {detaillab:'80321委屈3',detailhref:'www.baidu1.com'},
// {detaillab:'80问问6',detailhref:'www.baidu1.com'},]},
// ]
// },
// {tabtitle:"产品管理",tabhref:'www.baidu1.com',tablabel:[
// {tablabName:'发布产品',tablabHerf:'www.baidu.com'},
// {tablabName:'管理产品',tablabHerf:'www.baidu.com'},
// {tablabName:'回收站',tablabHerf:'www.baidu.com'},
// ],
// tabcontent:[
// {title:'发布产品',href:'www.baidu.com',detail:[
// {detaillab:'发布产品',detailhref:'www.baidu1.com'},
// {detaillab:'806',detailhref:'www.baidu1.com'},]},
// {title:'管理产品',href:'www.baidu.com',detail:[
// {detaillab:'管理产品',detailhref:'www.baidu1.com'},
// {detaillab:'8321嗯去为06',detailhref:'www.baidu1.com'},]},
// {title:'回收站',href:'www.baidu.com',detail:[
// {detaillab:'回收站',detailhref:'www.baidu1.com'},
// {detaillab:'803216',detailhref:'www.baidu1.com'},]},
// {title:'创造性',href:'www.baidu.com',detail:[
// {detaillab:'80321委屈3',detailhref:'www.baidu1.com'},
// {detaillab:'80问问6',detailhref:'www.baidu1.com'},]},
// ]
// },
// {tabtitle:"案例管理",tabhref:'www.baidu2.com',tablabel:[
// {tablabName:'发布案例',tablabHerf:'www.baidu.com'},
// {tablabName:'管理案例',tablabHerf:'www.baidu.com'},
// {tablabName:'回收站',tablabHerf:'www.baidu.com'},
// ],
// tabcontent:[
// {title:'发布案例',href:'www.baidu.com',detail:[
// {detaillab:'发布案例',detailhref:'www.baidu1.com'},
// {detaillab:'806',detailhref:'www.baidu1.com'},]},
// {title:'管理案例',href:'www.baidu.com',detail:[
// {detaillab:'管理案例',detailhref:'www.baidu1.com'},
// {detaillab:'8321嗯去为06',detailhref:'www.baidu1.com'},]},
// {title:'回收站',href:'www.baidu.com',detail:[
// {detaillab:'回收站',detailhref:'www.baidu1.com'},
// {detaillab:'803216',detailhref:'www.baidu1.com'},]},
// {title:'就如同',href:'www.baidu.com',detail:[
// {detaillab:'80321委屈3',detailhref:'www.baidu1.com'},
// {detaillab:'80问问6',detailhref:'www.baidu1.com'},]},
// ]
// },
// {tabtitle:"商机&客户中心",tabhref:'www.baidu3.com',tablabel:[
// {tablabName:'询盘',tablabHerf:'www.baidu.com'},
// {tablabName:'设置',tablabHerf:'www.baidu.com'},
// {tablabName:'test12',tablabHerf:'www.baidu.com'},
// ],
// tabcontent:[
// {title:'询盘',href:'www.baidu.com',detail:[
// {detaillab:'询盘',detailhref:'www.baidu1.com'},
// {detaillab:'806',detailhref:'www.baidu1.com'},]},
// {title:'设置',href:'www.baidu.com',detail:[
// {detaillab:'设置',detailhref:'www.baidu1.com'},
// {detaillab:'8321嗯去为06',detailhref:'www.baidu1.com'},]},
// {title:'就好地方',href:'www.baidu.com',detail:[
// {detaillab:'80请问3',detailhref:'www.baidu1.com'},
// {detaillab:'803216',detailhref:'www.baidu1.com'},]},
// {title:'新杯就如同j方',href:'www.baidu.com',detail:[
// {detaillab:'80321委屈3',detailhref:'www.baidu1.com'},
// {detaillab:'80问问6',detailhref:'www.baidu1.com'},]},
// ]
// },
// {tabtitle:"商家成长",tabhref:'www.baidu4.com',tablabel:[
// {tablabName:'商学院',tablabHerf:'www.baidu.com'},
// {tablabName:'test14',tablabHerf:'www.baidu.com'},
// {tablabName:'test15',tablabHerf:'www.baidu.com'},
// ],
// tabcontent:[
// {title:'商学院',href:'www.baidu.com',detail:[
// {detaillab:'803',detailhref:'www.baidu1.com'},
// {detaillab:'806',detailhref:'www.baidu1.com'},]},
// {title:'新西广泛大概方',href:'www.baidu.com',detail:[
// {detaillab:'80321',detailhref:'www.baidu1.com'},
// {detaillab:'8321嗯去为06',detailhref:'www.baidu1.com'},]},
// {title:'新南白大夫本人方',href:'www.baidu.com',detail:[
// {detaillab:'80请问3',detailhref:'www.baidu1.com'},
// {detaillab:'803216',detailhref:'www.baidu1.com'},]},
// {title:'广泛的',href:'www.baidu.com',detail:[
// {detaillab:'80321委屈3',detailhref:'www.baidu1.com'},
// {detaillab:'80问问6',detailhref:'www.baidu1.com'},]},
// ]
// },
// {tabtitle:"交易管理",tabhref:'www.baidu5.com',tablabel:[
// {tablabName:'test16',tablabHerf:'www.baidu.com'},
// {tablabName:'test17',tablabHerf:'www.baidu.com'},
// {tablabName:'test18',tablabHerf:'www.baidu.com'},
// ],
// tabcontent:[
// {title:'范文芳',href:'www.baidu.com',detail:[
// {detaillab:'803',detailhref:'www.baidu1.com'},
// {detaillab:'806',detailhref:'www.baidu1.com'},]},
// {title:'发生的',href:'www.baidu.com',detail:[
// {detaillab:'80321',detailhref:'www.baidu1.com'},
// {detaillab:'8321嗯去为06',detailhref:'www.baidu1.com'},]},
// {title:'新南五分方',href:'www.baidu.com',detail:[
// {detaillab:'80请问3',detailhref:'www.baidu1.com'},
// {detaillab:'803216',detailhref:'www.baidu1.com'},]},
// {title:'VS发生的的',href:'www.baidu.com',detail:[
// {detaillab:'80321委屈3',detailhref:'www.baidu1.com'},
// {detaillab:'80问问6',detailhref:'www.baidu1.com'},]},
// ]
// },
],
tabcontentShow:false,
tabcontent:'',
isActive:false,
};
},
methods:{
// 鼠标移入加入class
tabShow() {
this.tabcontentShow = true;
},
tabHide() {
this.tabcontentShow = false;
},
tabChange(content,index) {
this.tabcontentShow = true;
this.tabcontent = content;
this.isActive = index;
},
getList(){
axios('user/v1/menuTree','GET').then( res => {
this.tabList = res.data.data;
console.log(this.tabList);
}), err => {
console.log(err)
}
},
},
created() {
this.getList();
}
};
</script> <!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped > @import './index.css'; </style>

3.index.vue内的style部份代码如下:

@import './index.css';  //引入外联的index.css
4.index.css部份代码:
.tabNav {
width: 210px;
position: fixed;
top: 0;
bottom: 0;
margin-top: 64px;
background:rgba(247,248,250,1);
overflow: hidden;
z-index: 99;
} .tabs-content {
position: fixed;
top: 20px;
left:210px;
bottom: 0;
margin-top: 64px;
width:324px;
height:360px;
padding:0 24px;
float: left;
z-index: 99;
background:rgba(247,248,250,1);
border:1px solid rgba(196,198,207,1);
} .tabLeft{
min-width:180px;
height:67px;
background: #fff;
} .tabLeft:hover {
background:rgba(247,248,250,1);
border-bottom: 1px solid #ccc;
border-top: 1px solid #ccc;
} .tabTitle {
text-align: left;
padding-left: 16px;
padding-top: 12px;
font-size:14px;
font-family:PingFang-SC-Medium;
font-weight:500;
cursor: pointer;
color:rgba(51,51,51,1);
} .tabhref {
color:rgba(51,51,51,1);
} .tabhref:hover {
color: red;
transition: all 0.5s;
} .tabLabel {
width:50%;
font-size:12px;
font-family:PingFang-SC-Medium;
font-weight:500;
cursor: pointer;
text-align: left;
color:rgba(153,153,153,1);
} .tabLabel:hover {
color: red;
transition: all 0.5s;
} .tabLabelSon {
font-size:12px;
font-family:PingFang-SC-Medium;
font-weight:500;
text-align: left;
color:rgba(102,102,102,1);
} .tabDetail {
padding-top: 24px;
} .active {
border-left: solid rgba(27,191,196,1);
}

5.index.js部份代码如下:

import tabs from './index.vue';
import Vue from 'vue'
const Tabs = {
install:function() {
Vue.component('Tabs',tabs)
}
} export default Tabs;

6.再main.js里完成全局注册

import Tabs from './components/tab/index'
Vue.use(Tabs);
 
最后,在App.vue文件里引用
<Tabs/>  
至此,侧导航栏就会出现在所有的页面,初次封装,有什么问题的话希望提出指正!
 

使用vue封装一个tab栏切换的左侧导航栏的公共组件的更多相关文章

  1. 如何用vue封装一个防用户删除的平铺页面的水印组件

    需求 为了防止截图等安全问题,在web项目页面中生成一个平铺全屏的水印 要求水印内容为用户名,水印节点用户不能通过开发者工具等删除 效果 如上图 在body节点下插入水印DOM节点,水印节点覆盖在页面 ...

  2. 使用bootstrap3.0搭建一个具有自定义风格的侧边导航栏

    由于工作变动,新的项目组,可能会涉及到更多的类似于后台管理系统这一类的项目,而且开发可能更加偏向于传统型的开发,希望今后能够在新的项目中能够用得上vuejs吧! 接手项目的时候,就是一个后台管理系统, ...

  3. 一、简单的移动端tab头部二级下拉导航栏,向下弹出,向上隐藏

    一.简单的移动端tab头部二级下拉导航栏,向下弹出,向上隐藏 <html lang="en"> <head> <meta charset=" ...

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

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

  5. ElementUI 复杂顶部和左侧导航栏实现

    描述:如图 项目路径如下图所示: 代码实现: 首先在store.js中添加两个状态: import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vue ...

  6. ElementUI+命名视图实现复杂顶部和左侧导航栏

    在了解了命名视图的用途后,发现用命名视图来实现复杂导航更加省力.更多知识请参考这里 这里只说明重要配置内容,其他内容配置请参考上一篇初始版本: ElementUI 复杂顶部和左侧导航栏实现 或参考文末 ...

  7. iOS侧滑返回到隐藏导航栏的VC,导航栏会闪现一次

    VCA:是一个隐藏导航栏的页面:VCA在ViewWillAppear生命周期函数中设置导航栏隐藏: //隐藏导航栏 [self.navigationController setNavigationBa ...

  8. CI框架后台添加左侧导航栏出现的一系列问题

  9. Jquery实现动态导航栏和轮播导航栏

    动态导航栏和轮播导航栏的实现思想: 利用jquery技术的append()方法和bind()方法实现li标签的添加和点击事件绑定,在利用$getJSON(url,data,function)请求方法实 ...

随机推荐

  1. 数组实例 find和filter差异

    const list01 = [{'name':'No1',age:20},{'name':'No2',age:21},{'name':'No3',age:20}]; let list02 = lis ...

  2. 【MFC】CHtmlView或WebBrowser禁止脚本错误提示

    错误展示: 解决办法: 1.CHtmlView类或子类 CHtmlView::SetSilent(TRUE); 2.IWebBrowser2控件 IWebBrowser2::put_Silent(TR ...

  3. C++创建一个新的进程

    原文:http://blog.csdn.net/hk627989388/article/details/53309865 STARTUPINFO用于指定新进程的主窗口特性的一个结构. PROCESS_ ...

  4. Spring中的转换器:Converter

    配置spring的配置文件: <bean id="conversionService" class="org.springframework.context.sup ...

  5. Django中请求的生命周期 和 FBV模式和CBV模式

    Django的生命周期就是你的 一个请求所发生的整个流程 Django的生命周期内到底发生了什么呢?? . 当用户在浏览器中输入url时,浏览器会生成请求头和请求体发给服务端 请求头和请求体中会包含浏 ...

  6. 购买 In-app Billing 商品

    购买 In-app Billing 商品 一旦你的应用连接上了 Google Play,你就可以初始化内购商品的购买请求了.Google Play 提供了结算接口,可以让用户进入使用他们的支付方式,所 ...

  7. Python学习---django之ORM的增删改查180125

    模型常用的字段类型参数 <1> CharField        #字符串字段, 用于较短的字符串.        #CharField 要求必须有一个参数 maxlength, 用于从数 ...

  8. December 12th 2016 Week 51st Monday

    Nothing is impossible for a willing heart. 心之所愿,无所不成. I wish I can be a strong, clever, powerful and ...

  9. Tomcat服务时区设置

    tomcat服务不设置时间,会自动取系统时间,根据项目部署服务器位置不同时间会有差别,统一设置tomcat服务集群时间为东八区时间,具体设置如下: 在tomcat目录的bin文件夹下,找到文件cata ...

  10. python with原型

    @Python 的 with 语句详解   这篇文章主要介绍了Python 的 with 语句,本文详细讲解了with语句.with语句的历史.with语句的使用例子等,需要的朋友可以参考下   一. ...