index.vue 2.4KB

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