vant vue3 开发手机端网页vant vue 开发手机端网页vant tabbar双击显示

在封装vant tabba的组件中添加:

onBeforeMount(()=>{
    if (proxy.$route.name == "homeTop") {
        proxy.active = 0;
      } else if (proxy.$route.name == "car") {
        proxy.active = 1;
      } else{
        proxy.active = 2;
      }
    }
)

根据去往的路由对应的名字指定active的值

完整代码:

<template>
    <div>
        <van-tabbar v-model="active">
  <van-tabbar-item icon="home-o" to="/home/homeTop">首页</van-tabbar-item>
  <van-tabbar-item icon="shopping-cart-o" badge="1" to="/car">购物车</van-tabbar-item>
  <van-tabbar-item icon="friends-o">退出登陆</van-tabbar-item>
</van-tabbar>

    </div>
</template>

<script lang="ts">
     import {computed, defineComponent,ref,getCurrentInstance, onBeforeMount} from 'vue';

     export default defineComponent({
        setup(){
            let {proxy}:any=getCurrentInstance();
            let active=ref(0)
               onBeforeMount(()=>{
                   if (proxy.$route.name == "homeTop") {
                        proxy.active = 0;
                      } else if (proxy.$route.name == "car") {
                              proxy.active = 1;
                        } else{
                             proxy.active = 2;
                         }
                  }
                 )
                return{
                 active
                    }
           
        }

})
</script>

<style lang="less" scoped>

</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于Vue 3和Vant移动端TabBar的使用,你可以按照以下步骤进行操作: 1. 首先,确保你已经安装了Vue 3和Vant。你可以使用以下命令来安装它们: ```bash npm install vue@next vant ``` 2. 在你的Vue项目中,创建一个新的组件文件,例如`TabBar.vue`。 3. 在`TabBar.vue`文件中,引入VueVant的相关组件和样式: ```javascript <template> <div> <van-tabbar v-model="active"> <van-tabbar-item icon="home-o" to="/"> 首页 </van-tabbar-item> <van-tabbar-item icon="search" to="/search"> 搜索 </van-tabbar-item> <van-tabbar-item icon="star-o" to="/favorites"> 收藏 </van-tabbar-item> <van-tabbar-item icon="contact" to="/profile"> 个人中心 </van-tabbar-item> </van-tabbar> </div> </template> <script> import { Tabbar, TabbarItem } from 'vant'; export default { components: { [Tabbar.name]: Tabbar, [TabbarItem.name]: TabbarItem, }, data() { return { active: '/', }; }, }; </script> <style> /* 这里可以添加自定义样式 */ </style> ``` 4. 在你的主应用组件中,例如`App.vue`,使用`TabBar`组件: ```html <template> <div id="app"> <!-- 其他内容 --> <TabBar /> </div> </template> <script> import TabBar from './components/TabBar.vue'; export default { components: { TabBar, }, }; </script> <style> /* 这里可以添加全局样式 */ </style> ``` 5. 最后,你可以根据自己的需要在`TabBar.vue`中设置每个Tab项的图标、文字和链接。你还可以通过修改`active`的值来控制当前选中的Tab。 这样,你就可以在Vue 3项目中使用Vant移动端的TabBar了。记得根据自己的需求进行样式和功能的调整。希望对你有帮助!如果有任何问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值