index.vue 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <uni-shadow-root class="vant-tabbar-index"><view :class="'custom-class '+(border ? 'van-hairline--top-bottom' : '')+' '+(utils.bem('tabbar', { fixed, safe: safeAreaInsetBottom }))" :style="zIndex ? 'z-index: ' + zIndex : ''">
  3. <slot></slot>
  4. </view></uni-shadow-root>
  5. </template>
  6. <wxs src="../wxs/utils.wxs" module="utils"></wxs>
  7. <script>
  8. global['__wxRoute'] = 'vant/tabbar/index'
  9. import { VantComponent } from '../common/component';
  10. VantComponent({
  11. relation: {
  12. name: 'tabbar-item',
  13. type: 'descendant',
  14. linked(target) {
  15. this.children.push(target);
  16. target.parent = this;
  17. target.updateFromParent();
  18. },
  19. unlinked(target) {
  20. this.children = this.children.filter((item) => item !== target);
  21. this.updateChildren();
  22. }
  23. },
  24. props: {
  25. active: {
  26. type: null,
  27. observer: 'updateChildren'
  28. },
  29. activeColor: {
  30. type: String,
  31. observer: 'updateChildren'
  32. },
  33. inactiveColor: {
  34. type: String,
  35. observer: 'updateChildren'
  36. },
  37. fixed: {
  38. type: Boolean,
  39. value: true
  40. },
  41. border: {
  42. type: Boolean,
  43. value: true
  44. },
  45. zIndex: {
  46. type: Number,
  47. value: 1
  48. },
  49. safeAreaInsetBottom: {
  50. type: Boolean,
  51. value: true
  52. }
  53. },
  54. beforeCreate() {
  55. this.children = [];
  56. },
  57. methods: {
  58. updateChildren() {
  59. const { children } = this;
  60. if (!Array.isArray(children) || !children.length) {
  61. return Promise.resolve();
  62. }
  63. return Promise.all(children.map((child) => child.updateFromParent()));
  64. },
  65. onChange(child) {
  66. const index = this.children.indexOf(child);
  67. const active = child.data.name || index;
  68. if (active !== this.data.active) {
  69. this.$emit('change', active);
  70. }
  71. }
  72. }
  73. });
  74. export default global['__wxComponents']['vant/tabbar/index']
  75. </script>
  76. <style platform="mp-weixin">
  77. @import '../common/index.css';.van-tabbar{display:-webkit-flex;display:flex;width:100%;height:50px;height:var(--tabbar-height,50px);background-color:#fff;background-color:var(--tabbar-background-color,#fff)}.van-tabbar--fixed{position:fixed;bottom:0;left:0}.van-tabbar--safe{padding-bottom:env(safe-area-inset-bottom)}
  78. </style>