将四个主页面配置为 tab-bar 的子路由

本文详细描述了如何在Vue项目中使用Vant组件库构建一个带有路由功能的布局页面,包括默认子路由和tabbar导航栏的设计与配置。
摘要由CSDN通过智能技术生成

 使用vant组件库

路由

{
  path: '/',
name: 'layout',
    component: () => import('@/views/layout'),
  children: [
    {
      path: '', // 默认子路由
      name: 'home',
      component: () => import('@/views/home')
    },
    {
      path: 'qa',
      name: 'qa',
      component: () => import('@/views/qa')
    },
    {
      path: 'video',
      name: 'video',
      component: () => import('@/views/video')
    },
    {
      path: 'my',
      name: 'my',
      component: () => import('@/views/my')
    }
  ]
}

layout页面

<template>
  <div class="layout-container">
    <!-- 子路由出口 -->
    <router-view />
    <!-- /子路由出口 -->

    <!-- 标签导航栏 -->
    <!--
      route: 开启路由模式
     -->
    <van-tabbar class="layout-tabbar" route>
      <van-tabbar-item replace to="/">
        <!-- <template #icon="props"> -->
        <i slot="icon" class="iconfont icon-shouye"></i>
        <!-- </template> -->
        <span class="text">首页</span>
      </van-tabbar-item>
      <van-tabbar-item replace to="/qa" icon="search">
        <template #icon="props">
          <i class="iconfont icon-pinglun"></i>
        </template>
        <span class="text">问答</span>
      </van-tabbar-item>
      <van-tabbar-item replace to="/video" icon="home-o">
        <template #icon="props">
          <i class="iconfont icon-shipin"></i>
        </template>
        <span class="text"> 视频</span>
      </van-tabbar-item>
      <van-tabbar-item replace to="/my" icon="search">
        <template #icon="props">
          <i class="iconfont icon-wode"></i>
        </template>
        <span class="text"> 我的</span>
      </van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
export default {
  name: 'LayoutIndex',
  components: {

  },
  data() {
    return {

    };
  },
  created() {

  },
  mounted() {

  },
  methods: {

  },
}
</script>
<style scoped lang='less'>
.layout-container {
  .layout-tabbar {
    i.toutiao {
      font-size: 40px;
    }

    span.text {
      font-size: 20px;
    }
  }
}
</style>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值