使用vue封装一个tab栏切换的左侧导航栏的公共组件
首先看最终效果图:

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部份代码如下:
.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里完成全局注册
使用vue封装一个tab栏切换的左侧导航栏的公共组件的更多相关文章
- 如何用vue封装一个防用户删除的平铺页面的水印组件
需求 为了防止截图等安全问题,在web项目页面中生成一个平铺全屏的水印 要求水印内容为用户名,水印节点用户不能通过开发者工具等删除 效果 如上图 在body节点下插入水印DOM节点,水印节点覆盖在页面 ...
- 使用bootstrap3.0搭建一个具有自定义风格的侧边导航栏
由于工作变动,新的项目组,可能会涉及到更多的类似于后台管理系统这一类的项目,而且开发可能更加偏向于传统型的开发,希望今后能够在新的项目中能够用得上vuejs吧! 接手项目的时候,就是一个后台管理系统, ...
- 一、简单的移动端tab头部二级下拉导航栏,向下弹出,向上隐藏
一.简单的移动端tab头部二级下拉导航栏,向下弹出,向上隐藏 <html lang="en"> <head> <meta charset=" ...
- 微信小程序入门四: 导航栏样式、tabBar导航栏
实例内容 导航栏样式设置 tabBar导航栏 实例一:导航栏样式设置 小程序的导航栏样式在app.json中定义. 这里设置导航,背景黑色,文字白色,文字内容测试小程序 app.json内容: { & ...
- ElementUI 复杂顶部和左侧导航栏实现
描述:如图 项目路径如下图所示: 代码实现: 首先在store.js中添加两个状态: import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vue ...
- ElementUI+命名视图实现复杂顶部和左侧导航栏
在了解了命名视图的用途后,发现用命名视图来实现复杂导航更加省力.更多知识请参考这里 这里只说明重要配置内容,其他内容配置请参考上一篇初始版本: ElementUI 复杂顶部和左侧导航栏实现 或参考文末 ...
- iOS侧滑返回到隐藏导航栏的VC,导航栏会闪现一次
VCA:是一个隐藏导航栏的页面:VCA在ViewWillAppear生命周期函数中设置导航栏隐藏: //隐藏导航栏 [self.navigationController setNavigationBa ...
- CI框架后台添加左侧导航栏出现的一系列问题
- Jquery实现动态导航栏和轮播导航栏
动态导航栏和轮播导航栏的实现思想: 利用jquery技术的append()方法和bind()方法实现li标签的添加和点击事件绑定,在利用$getJSON(url,data,function)请求方法实 ...
随机推荐
- 浏览器根对象window之值为字符串的属性
1. string属性 1.1 origin window.origin使用返回的是当前网页的网址.打开百度首页,并在控制台中输入 window.origin 控制台中会输出"https:/ ...
- D3.js 入门教程
最近需要用到d3, 记录下d3的教程 网上搜了几个关于d3的教程 D3.js 入门教程 http://wiki.jikexueyuan.com/project/d3wiki/author.h ...
- Mybatis学习---Mybatis分页插件 - PageHelper
1. Mybatis分页插件 - PageHelper说明 如果你也在用Mybatis,建议尝试该分页插件,这个一定是最方便使用的分页插件. 该插件目前支持Oracle,Mysql,MariaDB,S ...
- ZT 线程处理函数pthread_cleanup_push / pthread_cleanup_pop
http://bbs.csdn.net/topics/390688105 2)创建了线程,但是线程退出时没有线程调用pthread_join() 线程资源没有回收,如果持续创建线程,到一定数量后将不能 ...
- Python 处理脚本的命令行参数(二):使用click
安装click pip install click 使用步骤 使用@click.command() 装饰一个函数,使之成为命令行接口 使用@click.option() 等装饰函数,为其添加命令行选项 ...
- mysql install steps
the official documents for mysql 5.6 install key steps: # Preconfiguration setup shell> groupadd ...
- IOS 了解新技术(UIPresentationController,屏幕适配)
1.了解有什么新技术1> 苹果API文档 - General - Guides - iOSx API Diffs2> 观看WWDC会议视频 2.如何使用新技术 1> 自己根据API文 ...
- Guava包学习---Bimap
Bimap也是Guava中提供的新集合类,别名叫做双向map,就是key->value,value->key,也就是你可以通过key定位value,也可以用value定位key. 这个场景 ...
- 【[NOI2010]航空管制】
关于拓扑排序的反建图还是一个非常套路的东西 比如说[HNOI2015]菜肴制作 我们希望使得某一个东西在拓扑序中出现的尽可能早,这个时候就可以建出一张反图来,使得这个东西在反图中的拓扑序尽量靠后,从而 ...
- hctf2018wp复现
1.bottle 登陆网站后存在提交url的地方 测试发生存在如下paload,知识点:1.crlf 2.写一个网站开发的端口小于80,浏览器就不会跳转能执行js(payload只能在火狐浏览器执行) ...