您的位置:首页 > Web前端 > Vue.js

Vue实现导航切换

2020-07-01 17:18 85 查看

Vue实现导航切换

<template>
<div>

<div class="dbox">
<span @click="go('/')" :class="{'active':isActive=='/'}">指令</span>
<span @click="go('/demo')" :class="{'active':isActive=='/demo'}">事件</span>
<span @click="go('/todolist')" :class="{'active':isActive=='/todolist'}">ToDolist</span>
<span @click="go('/liuyan')" :class="{'active':isActive=='/liuyan'}">留言板</span>
</div>

<router-view></router-view>

</div>
</template>

<script>
export default{
data(){
return{
isActive:window.location.pathname//默认被选中的导航的路由
}
},
methods:{
go(url){
this.$router.push({
path:url
})
this.isActive = url
}
}
}
</script>

<style scoped="scoped">
.dbox{
display: flex;
justify-content: space-around;
}
.active{
color: greenyellow;
}
span{
cursor: pointer;
}
</style>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: