我的GitHub前端经验总结,喜欢的话请点star:Thanks.: https://github.com/liangfengbo/frontend-develop
乳山网站建设公司创新互联建站,乳山网站设计制作,有大型网站制作公司丰富经验。已为乳山上千家提供企业网站建设服务。企业网站搭建\成都外贸网站建设公司要多少钱,请找那个售后服务好的乳山做网站的公司定做!
vuejs导航条高亮我的做法:
具体代码都在下面了
效果图:

html代码
data数据
// 导航条
data() {
return {
nav: [
{title: '首页', en: 'Code', path: '/'},
{title: '开源', en: 'Source', path: '/source'},
{title: '关于', en: 'About', path: '/about'},
],
navIndex: 0,
}
},
methods方法:
/**
* 路由跳转
* @param index
* @param link
*/
routerLink(index, path) {
// 点击哪个路由就赋值给自定义的下下标
this.navIndex = index;
// 路由跳转
this.$router.push(path)
},
/**
* 检索当前路径
* @param path
*/
checkRouterLocal(path) {
// 查找当前路由下标高亮
this.navIndex = this.nav.findIndex(item => item.path === path);
}
监听路由变化获取当前路由
watch: {
"$route"() {
// 获取当前路径
let path = this.$route.path;
// 检索当前路径
this.checkRouterLocal(path);
}
},
css样式
.nav-box {
display: flex;
}
.nav-item {
text-align: center;
padding: 0 32px;
position: relative;
display: inline-block;
font-size: 14px;
line-height: 25px;
}
/*导航普通状态*/
.item-cn {
color: #1c2438;
font-weight: 800;
}
/*导航普通状态*/
.item-en {
color: #666;
font-size: 12px;
}
/*导航高亮*/
.item-cn-active {
color: #2d8cf0;
}
/*导航高亮*/
.item-en-active {
color: #5cadff;
}
.nav-item:hover .item-cn {
color: #2d8cf0;
}
.nav-item:hover .item-en {
color: #5cadff;
}
.nav-item:after {
position: absolute;
right: 0;
top: 20px;
content: '';
width: 1px;
height: 16px;
background-color: #f8f8f8;
}
.nav-item:after:last-child {
width: 0;
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持创新互联。