vue如何实现自定义底部菜单栏
网络编程 2021-07-04 15:51www.168986.cn编程入门
这篇文章主要介绍了vue如何实现自定义底部菜单栏,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
最近vue不是特别火,自己想写一个vue 的底部菜单栏,然后试着开始写,起来还是听痛苦的,还是写出来,这个过程重查询了一些资料和看了一些视频。
1 写好界面
这是我写好的四个界面
2 在router.js重定义路由
在一级路由狼蚁网站SEO优化定义自己tabbr的子路由。
routes: [ { path: '/', name: 'index', ponent:()=>import('./views/index'), //懒加载引入,路由 children:[ {path:'',redirect:'/charts'},//重定项 {path:'/charts',name:'charts',ponent:()=>import('./views/charts.vue')}, {path:'/adiscover',name:'adiscover',ponent:()=>import('./views/adiscover.vue')}, {path:'/ybutton',ybutton:'ybutton',ponent:()=>import('./views/ybutton.vue')}, {path:'/me',name:'me',ponent:()=>import('./views/me.vue')} ] }, ]
3 封装tabbar底部菜单栏 组件
<template> <!-- <div class="footbar"> <router-link to='/' tag='div'> <span> <img :src="this.$route.path=='/charts'?'https://ss0.baidu./6ONWsjip0QIZ8tyhnq/it/u=3100024767,29226190&fm=58':'https://ss0.baidu./6ONWsjip0QIZ8tyhnq/it/u=3993527673,913427098&fm=58'" alt=""> </span> <span>资产</span> </router-link> <router-link to='/adiscover' tag='div'> <span> <img :src="this.$route.path=='/adiscover'?'https://10.url./qqcourse_logo_ng/ajNVdqHZLLAcYPom22osQf2IIdMD25ofYUibd1USSQFHdiaUIiavicpAibgSReIqCky8gqY8ku5qdXsc/356':'https://ss0.baidu./6ONWsjip0QIZ8tyhnq/it/u=3993527673,913427098&fm=58'" alt=""> </span> <span>商城</span> </router-link> <router-link to='/ybutton' tag='div'> <span> <img :src="this.$route.path=='/ybutton'?'https://10.url./qqcourse_logo_ng/ajNVdqHZLLAcYPom22osQf2IIdMD25ofYUibd1USSQFHdiaUIiavicpAibgSReIqCky8gqY8ku5qdXsc/356':'https://ss0.baidu./6ONWsjip0QIZ8tyhnq/it/u=3993527673,913427098&fm=58'" alt=""> </span> <span>交易</span> </router-link> <router-link to='/me' tag='div'> <span> <img :src="this.$route.path=='/me'?'https://10.url./qqcourse_logo_ng/ajNVdqHZLLAcYPom22osQf2IIdMD25ofYUibd1USSQFHdiaUIiavicpAibgSReIqCky8gqY8ku5qdXsc/356':'https://ss0.baidu./6ONWsjip0QIZ8tyhnq/it/u=3993527673,913427098&fm=58'" alt=""> </span> <span>我的</span> </router-link> </div> --> <div class="footer"> <router-link v-for="(item,index) in data" :key="index" :to="item.path"> <div class="divs" @click="tab_click(item.path)"> <i :class="item.icon==true?'red':'bloack'">1</i> <i>{{item.title}}</i> </div> </router-link> </div> </template> <script> import { constants } from 'crypto'; export default { props:{ data:Array }, data(){ return{ datai:this.data } }, created(){ }, mounted(){ console.log(this.data) }, methods:{ tab_click(path){ const that=this; let datary=this.data; for(let i=0;i<datary.length;i++){ datary[i].icon=false; if(datary[i].path==path){ datary[i].icon=true; console.log('---------',datary[i].path) } } this.datai=datary; console.log(datary) } } } </script> <style scoped> .footer{ position: fixed; bottom:0px; left:0px; width:100%; display:flex; justify-content: space-between; } .footer .divs{padding:10px;} .red{color:red;font-size:14px;} .bloack{font-size:14px;color:black;} / ---------------- / .footbar{ width: 100%; height: 2.613333rem; position: fixed; bottom: 0; display: flex; align-items: center; background: white; border-: 1px solid #eeeeee; color: #999999; } .footbar span{ display: block; font-size: .64rem; } .footbar div{ flex: 1; text-align: center; } .footbar img{ height: 1.066667rem; } .footbar .router-link-exact-active{ color: #2F83C3; } .footbar .active{ color: #2F83C3; } </style>
4 显示底部菜单栏的界面 引入tabbar 组件
<template> <div class="index"> 主页 <router-view></router-view> <tabbar :data="tabbarData"/> </div> </template> <script> import tabbar from '../ponents/tabbaer' export default { name:'index', data() { return { tabbarData:[ {title:'微信',icon:true,path:'/charts'}, {title:'通讯录',icon:false,path:'/adiscover'}, {title:'发现',icon:false,path:'/ybutton'}, {title:'我的',icon:false,path:'/me'}, ] } }, ponents:{ tabbar, }, } </script> <style scoped> .index{ width:100%; height:100%; overflow: hidden; padding:16px; box-sizing:border-box; } </style>
5 这就是最终结果
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指