底部菜单栏的实现

实现底部菜单栏页面的跳转以及显示页面的切换,如图

 实现代码如下

HTML

<!-- 底部菜单栏 -->
    <div class="bottom">
      <div id="d1" class="bottom-item" :class="{active: this.$route.path === '/'}" @click="change('/')">
        日记
      </div>
      <div id="d2" class="bottom-item" :class="{active: this.$route.path==='/mood'}" @click="change('mood')">
        心情贴
      </div>
      <div id="d3" class="bottom-item" :class="{active: this.$route.path==='/person'}" @click="change('person')">
        主页
      </div>
    </div>

JS

change(path) {
      console.log('path', path, this.$route.name)
      // 获取当前页面的路径名
      let thisUrl = this.$route.name
      // 当跳转路径为 '/',且当前页面不为 '/',实现跳转
      if(path === '/' && thisUrl !== "/") {
        this.$router.push('/')
      } else if(path === 'mood' && thisUrl !== "Mood") {
        this.$router.push('/mood')
      } else if(path === 'person' && thisUrl !== "Person") {
        this.$router.push('/person')
      }
    }

css

.bottom {
  width: 100%;
  height: 60px;
  background-color:rgb(191, 230, 191);
  position: fixed;
  left: 0;
  bottom: 0;
  border-top: 1px solid #ccc;
  div {
    display: inline-block;
    text-align: center;
    height: 60px;
    line-height: 60px;
    width: 32.5%;
    a {
        color: #333;
        text-decoration: none;
    }
  }
  // 显示当前所处页面
  .active {
    color: red;
    box-shadow: rgb(164, 221, 164) 1px 2px 5px 5px;
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值