当前位置:Gxlcms > JavaScript > vue组件tabbar使用方法详解

vue组件tabbar使用方法详解

时间:2021-07-01 10:21:17 帮助过:12人阅读

本文实例为大家分享了vue组件tabbar的具体使用方法,供大家参考,具体内容如下

1.App.vue

  1. <!-- 入口文件 -->
  2. <template>
  3. <div id="app">
  4. <!-- 视图层 -->
  5. <router-view></router-view>
  6. <!-- 底部选项卡 -->
  7. <tabbar @on-index-change="onIndexChange" v-if="tabbarShow">
  8. <tabbar-item selected link="/home">
  9. <img slot="icon" src="./assets/img/ic_tab_home_normal.png">
  10. <img slot="icon-active" src="./assets/img/ic_tab_home_active.png">
  11. <span slot="label">首页</span>
  12. </tabbar-item>
  13. <tabbar-item show-dot link="/audioBook">
  14. <img slot="icon" src="./assets/img/ic_tab_subject_normal.png">
  15. <img slot="icon-active" src="./assets/img/ic_tab_subject_active.png">
  16. <span slot="label">书影音</span>
  17. </tabbar-item>
  18. <tabbar-item badge="2" link="/mine">
  19. <img slot="icon" src="./assets/img/ic_tab_profile_normal.png">
  20. <img slot="icon-active" src="./assets/img/ic_tab_profile_active.png">
  21. <span slot="label">我的</span>
  22. </tabbar-item>
  23. </tabbar>
  24. </div>
  25. </template>
  26. <script>
  27. // 引入 vux tabbar 组件
  28. import { Tabbar, TabbarItem } from 'vux'
  29. // 引入 vuex 的两个方法
  30. import {mapGetters, mapActions} from 'vuex'
  31. export default {
  32. name: 'app',
  33. components:{
  34. Tabbar,
  35. TabbarItem
  36. },
  37. data() {
  38. return {
  39. select:"Home"
  40. }
  41. },
  42. // 计算属性
  43. computed:mapGetters([
  44. // 从 getters 中获取值
  45. 'tabbarShow'
  46. ]),
  47. // 监听,当路由发生变化的时候执行
  48. watch:{
  49. $route(to,from){
  50. if(to.path == '/' || to.path == '/home' || to.path == '/audioBook' || to.path == '/mine'){
  51. /**
  52. * $store来自Store对象
  53. * dispatch 向 actions 发起请求
  54. */
  55. this.$store.dispatch('showTabBar');
  56. }else{
  57. this.$store.dispatch('hideTabBar');
  58. }
  59. }
  60. },
  61. methods: {
  62. onIndexChange (newIndex, oldIndex) {
  63. console.log(newIndex, oldIndex);
  64. }
  65. }
  66. }
  67. </script>
  68. <style lang="less" scoped>
  69. </style>

2.效果图

3.其他情况

  1. <template>
  2. <div class="weui-tab">
  3. <div class="weui-tab__panel">
  4. <p v-for="i in 100">{{i}}</p>
  5. </div>
  6. <tabbar>
  7. <!--use v-link-->
  8. <tabbar-item v-link="{path:'/component/cell'}">
  9. <img slot="icon" src="../assets/demo/icon_nav_button.png">
  10. <span slot="label">Wechat</span>
  11. </tabbar-item>
  12. <!--use http link-->
  13. <tabbar-item show-dot link="https://vux.li">
  14. <img slot="icon" src="../assets/demo/icon_nav_msg.png">
  15. <span slot="label">Message</span>
  16. </tabbar-item>
  17. <!--use vue-router link-->
  18. <tabbar-item selected link="/component/cell">
  19. <img slot="icon" src="../assets/demo/icon_nav_article.png">
  20. <span slot="label">Explore</span>
  21. </tabbar-item>
  22. <!--use vue-router object link-->
  23. <tabbar-item :link="{path:'/component/cell'}">
  24. <img slot="icon" src="../assets/demo/icon_nav_cell.png">
  25. <span slot="label">News</span>
  26. </tabbar-item>
  27. </tabbar>
  28. </div>
  29. </template>
  30. <script>
  31. import { Tabbar, TabbarItem } from 'vux'
  32. export default {
  33. ready () {
  34. document.querySelector('body').style.height = '100%'
  35. document.querySelector('html').style.height = '100%'
  36. document.querySelector('#app').style.height = '100%'
  37. },
  38. components: {
  39. Tabbar,
  40. TabbarItem
  41. }
  42. }
  43. </script>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

人气教程排行