vant 底部导航组件的实现(tabbar)

本文介绍了一个使用Vue框架实现的Tabbar组件代码示例,详细展示了如何通过Vanilla UI库创建响应式底部导航栏,包括图标状态切换和路由跳转等功能。
<template>
  <van-tabbar v-model="active" class="active_tab">
    <van-tabbar-item
      v-for="(item,index) in tabbars"
      :key="index"
      @click="tab(index,item.name)"
    >
      <span :class="currIndex == index ? active:''">{{item.title}}</span>
      <template slot="icon" slot-scope="props">
        <img :src="props.active ? item.active : item.normal">
      </template>
    </van-tabbar-item>
  </van-tabbar>
</template>

<script>
export default {
  name: "tabbar",
  data() {
    return {
      currIndex: 0,
      active: 0,
      tabbars: [
        {
          name: "home",
          title: "首页",
          normal: require("../common/icon/home.png"),
          active: require("../common/icon/home_ac.png")
        },
        {
          name: "category",
          title: "分类",
          normal: require("../common/icon/category.png"),
          active: require("../common/icon/category_ac.png")
        },
        {
          name: "message",
          title: "消息",
          normal: require("../common/icon/message.png"),
          active: require("../common/icon/message.png")
        },
        {
          name: "cart",
          title: "购物车",
          normal: require("../common/icon/cart.png"),
          active: require("../common/icon/cart_ac.png")
        },
        {
          name: "mine",
          title: "我的",
          normal: require("../common/icon/mine.png"),
          active: require("../common/icon/mine_ac.png")
        }
      ]
    };
  },
  methods: {
    tab(index, val) {
      this.currIndex = index;
      this.$router.push(val);
    }
  }
};
</script>

<style lang="scss" scoped>
.active_tab img {
  width: 26px;
  height: 26px;
}

.van-tabbar-item--active {
  color: #e10f02;
}
</style>

转载自:https://www.cnblogs.com/Jasonpub/p/10592390.html

如果您使用的是 Vue.js 框架,并且使用的是 vant UI 组件库中的 Dialog 对话框组件,那么您可以通过设置对话框组件的 `overlay` 属性来实现遮盖底部tabbar。 具体来说,您可以将 `overlay` 属性设置为 `true`,这样对话框组件就会显示一个半透明的背景遮盖住整个页面,包括底部tabbar。示例代码如下: ```html <van-dialog v-model="show" title="标题" :overlay="true" :lock-scroll="false" @confirm="handleConfirm" @cancel="handleCancel" > <p>对话框内容</p> </van-dialog> ``` 在上面的示例代码中,我们将 `overlay` 属性设置为 `true`,这样对话框组件就会显示一个半透明的背景遮盖住整个页面,包括底部tabbar。另外,我们还设置了对话框组件的标题和内容,并且监听了 `confirm` 和 `cancel` 事件,用于处理用户点击确认和取消按钮后的操作。 需要注意的是,如果您想要在对话框组件弹出时隐藏底部tabbar,可以在组件的 `show` 属性发生变化时,通过调用底部 tabbar 的 `hide` 方法来实现。示例代码如下: ```html <van-dialog v-model="show" title="标题" :overlay="true" :lock-scroll="false" @confirm="handleConfirm" @cancel="handleCancel" @show="handleShow" @hide="handleHide" > <p>对话框内容</p> </van-dialog> ``` ```javascript export default { data() { return { show: false } }, methods: { handleShow() { this.$refs.tabbar.hide() }, handleHide() { this.$refs.tabbar.show() }, handleConfirm() { // 处理确认按钮点击后的操作 }, handleCancel() { // 处理取消按钮点击后的操作 } } } ``` 在上面的示例代码中,我们监听了对话框组件的 `show` 和 `hide` 事件,并且在 `show` 事件中调用了底部 tabbar 的 `hide` 方法,将其隐藏起来。在 `hide` 事件中则相反,调用了底部 tabbar 的 `show` 方法,将其显示出来。这样就可以避免对话框组件遮盖底部tabbar 了。
评论 11
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值