vue 底部导航栏组件

- 日理万妓 2021-07-24 23:23 634阅读 0赞
  1. bug:
  2. 因为通过router-link跳转,所以只能点击文字跳转,将router-link换成其他标签,然后设置跳转事件能改变这一bug
  3. 因为非引入static内的图片,得用require引入

效果:
在这里插入图片描述
代码示例:

  1. <template>
  2. <div class='foot'>
  3. <div class='nav'>
  4. <img :src="$route.path=='/home'?require('../../assets/tabs/1.png'):require('../../assets/tabs/2.png')" alt="">
  5. <router-link :to="{name:'home'}" :class="{colo:$route==='/home'}">外卖</router-link>
  6. </div>
  7. <div class='nav'>
  8. <img :src="$route.path=='/search'?require('../../assets/tabs/3.png'):require('../../assets/tabs/4.png')" alt="">
  9. <router-link :to="{name:'search'}">搜索</router-link>
  10. </div>
  11. <div class='nav'>
  12. <img :src="$route.path=='/order'?require('../../assets/tabs/5.png'):require('../../assets/tabs/6.png')" alt="">
  13. <router-link :to="{name:'order'}">订单</router-link>
  14. </div>
  15. <div class='nav'>
  16. <img :src="$route.path=='/person'?require('../../assets/tabs/7.png'):require('../../assets/tabs/8.png')" alt="">
  17. <router-link :to="{name:'person'}">我的</router-link>
  18. </div>
  19. </div>
  20. </template>
  21. <script>
  22. export default{
  23. data()
  24. {
  25. return{
  26. }
  27. },
  28. methods:{
  29. }
  30. }
  31. </script>
  32. <style scoped>
  33. .foot>div>a{
  34. color: #bfbfbf;
  35. text-decoration: none;
  36. }
  37. .foot>div>a.active{
  38. color:#42af08;
  39. }
  40. .foot{
  41. height: 50px;
  42. width: 100%;
  43. position: absolute;
  44. bottom: 0;
  45. display: flex;
  46. }
  47. .foot>div{
  48. text-align: center;
  49. flex:1;
  50. }
  51. .foot>div>img{
  52. height: 30px;
  53. width: 30px;
  54. display: block;
  55. margin: 0 auto;
  56. }
  57. </style>

无bug版本:

  1. <template>
  2. <div class='tabbar'>
  3. <router-link to="/home">
  4. <img :src="$route.path=='/home'?'https://dss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1091405991,859863778&fm=26&gp=0.jpg':'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=4025634963,2730768284&fm=26&gp=0.jpg'" alt="">
  5. <p>首页</p>
  6. </router-link>
  7. <router-link to="/category">
  8. <img :src="$route.path=='/category'?'https://dss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1091405991,859863778&fm=26&gp=0.jpg':'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=4025634963,2730768284&fm=26&gp=0.jpg'" alt="">
  9. <p>分类</p>
  10. </router-link>
  11. <router-link to="shopcar">
  12. <img :src="$route.path=='/shopcar'?'https://dss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1091405991,859863778&fm=26&gp=0.jpg':'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=4025634963,2730768284&fm=26&gp=0.jpg'" alt="">
  13. <p>购物车</p>
  14. </router-link>
  15. <router-link to="mine">
  16. <img :src="$route.path=='/mine'?'https://dss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1091405991,859863778&fm=26&gp=0.jpg':'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=4025634963,2730768284&fm=26&gp=0.jpg'" alt="">
  17. <p>我的</p>
  18. </router-link>
  19. </div>
  20. </template>
  21. <script>
  22. export default {
  23. name:'tabbar',
  24. data(){
  25. return{
  26. }
  27. },
  28. }
  29. </script>
  30. <style scoped>
  31. .tabbar>.router-link-active{
  32. color:red
  33. }
  34. .tabbar>a{
  35. text-decoration: none;
  36. color:black;
  37. flex:1;
  38. text-align: center;
  39. }
  40. .tabbar>a>p{
  41. margin: 0;
  42. }
  43. .tabbar>a>img{
  44. width:50px;
  45. height: 50px;
  46. }
  47. .tabbar{
  48. display: flex;
  49. position: fixed;
  50. left: 0;
  51. bottom:0;
  52. width:100%;
  53. }
  54. </style>

在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,634人围观)

还没有评论,来说两句吧...

相关阅读

    相关 底部导航

    1.添加相应的文件 2.分别加入4个Fragment以及布局文件 3.MianActivity的引用 4.MainActivity的布局文件   添加相应的文件:

    相关 Vue开发精要之底部导航

    Vue开发精要之底部导航栏 > 在我们日常开发中,尤其是移动端开发(`H5`、`微信公众号`、`企业微信`等)中,我们往往需要自己设计底部导航栏。或许,导航栏这种常见