k-tabbar.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <!-- 底部导航栏 -->
  3. <u-tabbar class="u-tabbar" :fixed="fixed" :placeholder="placeholder" :safeAreaInsetBottom="safeAreaInsetBottom"
  4. :value="$S_tabbar_tabIdx" @change="tabChg">
  5. <u-tabbar-item v-for="item in tabList" :key="item.id" :text="item.name" :icon="item.icon"></u-tabbar-item>
  6. </u-tabbar>
  7. </template>
  8. <script>
  9. /**
  10. * tabbar 底部导航栏
  11. * @description 本组件主要是对uview的tabbar的二次封装。
  12. *
  13. * @property {Boolean} fixed 是否固定在底部 (默认 true )
  14. * @property {Boolean} placeholder fixed定位固定在底部时,是否生成一个等高元素防止塌陷 (默认 true )
  15. * @property {Boolean} safeAreaInsetBottom 是否为iPhoneX留出底部安全距离 (默认 true )
  16. * @property {Array<Object>} tabList 底部导航栏的数组,用于渲染导航栏数据
  17. *
  18. * @event {Function} tabChg 底部导航栏切换
  19. */
  20. export default {
  21. props: {
  22. fixed: {
  23. type: Boolean,
  24. default: true
  25. },
  26. placeholder: {
  27. type: Boolean,
  28. default: true
  29. },
  30. safeAreaInsetBottom: {
  31. type: Boolean,
  32. default: true
  33. },
  34. tabList: {
  35. type: Array,
  36. default: [{
  37. name: '首页',
  38. icon: 'home',
  39. id: 1
  40. },
  41. {
  42. name: '购物车',
  43. icon: 'car',
  44. id: 2
  45. },
  46. {
  47. name: '我的',
  48. icon: 'account',
  49. id: 3
  50. }
  51. ]
  52. }
  53. },
  54. computed: {
  55. $S_tabbar_tabIdx() {
  56. return this.$store.state.common.$S_tabbar_tabIdx || 0;
  57. }
  58. },
  59. methods: {
  60. // 底部导航栏切换
  61. tabChg(e) {
  62. // 如果存在vuex
  63. if (this.$store) {
  64. // 操作vuex改变数据(这个方法可以根据自己需要改动)
  65. this.$store.dispatch('ACTI_TABIDX', e);
  66. }
  67. // 向父组件传递数据
  68. this.$emit('tabChg', e);
  69. }
  70. }
  71. };
  72. </script>