我自己用vue做的一个小组件,同时加类名和跳转页。请老师帮忙看下问题
<template>
<div class="sidebar">
<ul class="sidebar-items">
<li :class="{ focus: index == current}" @click="changeColor_Page"
v-for="(item, index) in list"
:key="index"
:ref="index"
>{{item}}
<input type="hidden" :value="index">
</li>
</ul>
</div>
</template>
<script>
export default {
name: 'FamilySidebar',
data () {
return {
current: 0,
value: '',
list: ['员工基本信息', '员工家庭情况', '证件情况', '生育记录',
'就职情况', '购保情况', '公积金购买', '相关技术证书档案', '工作证件办理记录',
'免搭伙食', '补助']
}
},
methods: {
changeColor_Page (e) {
this.color(e)
this.page(e)
},
color (e) {
console.log('current :', this.current)
console.log('value :', e.target.children[0].value)
this.current = e.target.children[0].value
},
page (e) {
if (e.target.innerText === '员工基本信息') {
this.$router.push('/')
}
if (e.target.innerText === '员工家庭情况') {
this.$router.push('/family')
}
if (e.target.innerText === '证件情况') {
this.$router.push('/certificate')
}
if (e.target.innerText ==='生育记录') {
this.$router.push('/birth')
}
}
}
}
</script>
<style scoped>
.sidebar
position: relative
width: 200px
height: 840px
background-color: #393b6b
.sidebar-items
display: flex
flex-direction: column
justify-content: space-between
position: absolute
left: 0
li
margin-left: -40px
width: 200px
height: 40px
line-height: 40px
color: #abb3ec
padding-left: 30px
cursor: pointer
.focus
background-color: #2c2c50
padding-left: 0;
</style>我这个功能是这样的,点击选项的时候,同时给被的 li 加上类名,然后跳转。但会出现点击两次才给加上类名,不过已经实现跳转。其余没跳转功能的选项则点击一次就加上类名。老师能说下为什么会这样吗》?还有该如何解决
0
收起
正在回答
1回答
你好同学,老师这边大量测试,没有出现同学描述的情况。效果是这样的:
当点击首页没有绑定的路由的菜单,可以切换样式。当点击绑定路由的菜单时,已经跳转到其他子页面,所以首页切换样式也是看不到的。当点击返回首页的时候,因为已经离开了子页面,所以此时默认第一个菜单有样式是合理的,没有问题哦
祝学习愉快 ,望采纳。
热门框架Vue开发WebApp 18版
- 参与学习 人
- 提交作业 209 份
- 解答问题 3299 个
本路径是通过ES6基础知识、运用Zepto、Swiper、fullPag等移动端常用工具包、以及当下流行框架Vue,结合多个实战案例,还原真实开发场景,最终实现手机端购物商城网页开发。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星