写vue项目自定义tab主页

做出来的效果图

底部tab页面自定义效果

1、首先定义路由

在路由index.js页面中定义五个子路由,如图


Vue.use(VueRouter)

  const routes = [
    
  {
    path: '/',
    redirect: '/index'
  },
 {
    path:'/index',
    name:'Index',
    redirect:'/home',
    component:Index,
    children:[
      {
        path:'/home',
        name:'Home',
        component:Home
      },
      {
        path:'/plan',
        name:'Plan',
        component:Plan
      },
      {
        path:'/clock',
        name:'Clock',
        component:Clock
      },
      {
        path:'/free',
        name:'Free',
        component:Free
      },
      {
        path:'/user',
        name:'User',
        component:User
      }
    ]
  },
2.其中主页面Index.vue页面中代码如图
<template>
    <div>
        <div id="container" >
            <!-- 视图容器 -->
            <router-view></router-view>
        </div>
        <div class="bottom-tab">
            <div class="tab-item" @click="switchTo('/home')">
                    <img :src="'/home' === $route.path ? tabBarImgArr[0].selected : tabBarImgArr[0].normal" alt="首页">
                    <span :class="{on: '/home' === $route.path}">首页</span>
                </div>
            <div class="tab-item" @click="switchTo('/plan')">
                    <img :src="'/plan' === $route.path ? tabBarImgArr[1].selected : tabBarImgArr[1].normal" alt="计划">
                    <span :class="{on: '/plan' === $route.path}">计划</span>
                </div>
            <div class="tab-item" @click="switchTo('/free')">
                    <img :src="'/free' === $route.path ? tabBarImgArr[2].selected : tabBarImgArr[2].normal" alt="免费领" class="bigimg">
                    <span :class="{on: '/free' === $route.path}">免费领</span>
                </div>
            <div class="tab-item" @click="switchTo('/clock')">
                    <img :src="'/clock' === $route.path ? tabBarImgArr[3].selected : tabBarImgArr[3].normal" alt="打卡">
                    <span :class="{on: '/clock' === $route.path}">打卡</span>
                </div>
            <div class="tab-item" @click="switchTo('/user')">
                    <img :src="'/user' === $route.path ? tabBarImgArr[4].selected : tabBarImgArr[4].normal" alt="我的">
                    <span :class="{on: '/user' === $route.path}">我的</span>
                </div>
        </div>
    </div>
</template>
<script>
export default {
    data(){
        return {
            tabBarImgArr:[   //图片切换
                {normal: require('../../styles/img/tabimg/home_1.png'), selected: require('../../styles/img/tabimg/home.png')},
                {normal: require('../../styles/img/tabimg/plan_1.png'), selected: require('../../styles/img/tabimg/plan.png')},
                {normal: require('../../styles/img/tabimg/content.png'), selected: require('../../styles/img/tabimg/content.png')},
                {normal: require('../../styles/img/tabimg/clock_1.png'), selected: require('../../styles/img/tabimg/clock.png')},
                {normal: require('../../styles/img/tabimg/user_1.png'), selected: require('../../styles/img/tabimg/user.png')}
            ]
        }
    },
    methods:{
    switchTo(path){
      // console.log(this.$router)
      this.$router.replace(path)
    }
  }
}
</script>
<style scoped>
.bottom-tab{
    width:100%;
    height:126px;
    background-color:#fff;
    position:fixed;
    left :0px;
    bottom :0px;
    display :flex;
    z-index :999;
    box-shadow:0px 0px 8px 0px rgba(213,213,213,0.24);
    }
.tab-item{
    display:flex;
    flex:1;
    flex-direction:column;
    align-items:center;
    justify-content:center;
    font-size:22px;
    color:#666;
}
.tab-item img{
        width: 44px;
        height: 44px;
        margin-bottom:2px;
}
.tab-item .bigimg{
        width: 90px;
        height: 90px;
        margin-bottom:0px;
        margin-top: -45px;
}
.on{
        color :#FECC35; 
}
        
        
      
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值