vue里面的底部菜单

<template>
    <div class="mui-row">
        <div class="mui-col-xs-12 mui-row nav">
            <div class="mui-col-xs-4" @tap="tab1=1;tab2=1;tab3=1">
                <router-link to="/recommend" ><img :src="'img/tabIcon/tab1'+tab1+'.png'" @tap="tab1=1;tab2=1;tab3=1"/><span class="mui-tab-label"  @tap="tab1=1;tab2=1;tab3=1">{{"推荐好课" | title}}</span></router-link>
            </div>
            <div class="mui-col-xs-4" @tap="tab2=2;tab1=2;tab3=1">
                <router-link :to="{path: '/Broadcast/' +(tabNum=tabNum==undefined?0:tabNum)}"><img :src="'img/tabIcon/tab2'+tab2+'.png'" @tap="tab2=2;tab1=2;tab3=1"/><span class="mui-tab-label"  @tap="tab2=2;tab1=2;tab3=1">{{"师道直播" | title}}</span></router-link>
            </div>
            <div class="mui-col-xs-4" @tap="tab3=2;tab1=2;tab2=1">
                <router-link to="/my"><img :src="'img/tabIcon/tab3'+tab3+'.png'" @tap="tab3=2;tab1=2;tab2=1"/><span class="mui-tab-label"  @tap="tab3=2;tab1=2;tab2=1">{{"我" | title}}</span></router-link>
            </div>
        </div>
    </div> 
    
</template>
<style scoped>
    .mui-row { background: #FFF; border-top:1px solid #F5F5F5; }
    .mui-col-xs-12 .mui-col-xs-4 { text-align: center; height: 50px; }
    img{position:relative; top:0px; width: 30px; height: 30px; padding-top: 0; padding-bottom: 0; }
    .mui-tab-label{ font-size: 11px; display: block; overflow: hidden; text-overflow: ellipsis; margin-top: -7px; }
    a{color:#b9b5b5;}
    .mui-bar{ -webkit-box-shadow: 0 0 1px rgba(222, 219, 219, 0.85); box-shadow: 0 0 1px rgba(222, 219, 219, 0.85); }
    .mui-row .router-link-exact-active.router-link-active{ color:#3FCDFF; } 
    .mui-col-xs-12 .mui-col-xs-4 a{height: 50px; display: inline-block; width: 100%;}
</style>
<script>
 export default {
        created() {
         this.$route.params.tabNum=0;
        },
        mounted() {
        if(this.$route.params.tabNum!='undefined'){
		       this.tabNum=this.$route.params.tabNum;//因为这个切换选项卡就path改变了
            }
        	else{
        		this.tabNum=0;	
        	}	

         if(this.$route.path=='/my'){
         	this.tab3=2;this.tab1=2;this.tab2=1
         }
         else if(this.$route.path=='/Broadcast/'+this.tabNum){//因为这里的path是随着选项卡切换改变的。所以要写成动态的。
         	this.tab2=2;this.tab1=2;this.tab3=1
         }else{
         	this.tab1=1;this.tab2=1;this.tab3=1
         }
     	 
        },
        beforeRouteEnter(to, from, next) {
        //	console.log(to)
        //     if (to.params.db == null) {
        //         return next({ name: "", params: { id: to.params.id } });
        //     }
        //     next();
           },
        components: {},
        data() {
            return {
               tabNum:0,
               tab1:1,
               tab2:1,
               tab3:1,
            }
        },

        methods: {
     
        },
        watch:{
        	 "$route.params"(tab){ //
			       this.tabNum=this.$route.params.tabNum;
            },
             
        	}
    }
</script>

我的几个图标是这样的。

最终的效果点击那个那个就变成蓝色的。并且进入子页面再切出来他还是蓝色的。

Vue可以通过使用组件实现底部菜单功能,以下是一个简单的实现方式: 1. 创建一个菜单组件 ```vue <template> <div class="bottom-menu"> <router-link :to="item.link" v-for="item in menuItems" :key="item.id"> <div class="menu-item"> <i :class="item.icon"></i> <span class="menu-text">{{ item.text }}</span> </div> </router-link> </div> </template> <script> export default { data() { return { menuItems: [ { id: 1, text: "首页", icon: "icon-home", link: "/" }, { id: 2, text: "分类", icon: "icon-category", link: "/category" }, { id: 3, text: "购物车", icon: "icon-cart", link: "/cart" }, { id: 4, text: "我的", icon: "icon-user", link: "/user" } ] }; } }; </script> <style scoped> .bottom-menu { display: flex; justify-content: space-around; padding: 10px; background-color: #fff; border-top: 1px solid #f0f0f0; position: fixed; bottom: 0; left: 0; width: 100%; } .menu-item { display: flex; flex-direction: column; align-items: center; font-size: 12px; color: #666; } .menu-item i { font-size: 22px; margin-bottom: 3px; } .menu-item.active { color: #ff6d00; } </style> ``` 2. 在页面中引入菜单组件 ```vue <template> <div class="page"> <router-view></router-view> <bottom-menu></bottom-menu> </div> </template> <script> import BottomMenu from "@/components/BottomMenu.vue"; export default { components: { BottomMenu } }; </script> ``` 通过以上两步,就可以在页面底部显示出一个包含多个菜单项的底部菜单。当用户点击菜单项时,可以通过Vue Router实现页面的跳转。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值