index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { getRect } from '../common/utils';
  2. import { VantComponent } from '../common/component';
  3. VantComponent({
  4. relation: {
  5. name: 'tabbar-item',
  6. type: 'descendant',
  7. current: 'tabbar',
  8. linked(target) {
  9. target.parent = this;
  10. target.updateFromParent();
  11. },
  12. unlinked() {
  13. this.updateChildren();
  14. },
  15. },
  16. props: {
  17. active: {
  18. type: null,
  19. observer: 'updateChildren',
  20. },
  21. activeColor: {
  22. type: String,
  23. observer: 'updateChildren',
  24. },
  25. inactiveColor: {
  26. type: String,
  27. observer: 'updateChildren',
  28. },
  29. fixed: {
  30. type: Boolean,
  31. value: true,
  32. observer: 'setHeight',
  33. },
  34. placeholder: {
  35. type: Boolean,
  36. observer: 'setHeight',
  37. },
  38. border: {
  39. type: Boolean,
  40. value: true,
  41. },
  42. zIndex: {
  43. type: Number,
  44. value: 1,
  45. },
  46. safeAreaInsetBottom: {
  47. type: Boolean,
  48. value: true,
  49. },
  50. },
  51. data: {
  52. height: 50,
  53. },
  54. methods: {
  55. updateChildren() {
  56. const { children } = this;
  57. if (!Array.isArray(children) || !children.length) {
  58. return;
  59. }
  60. children.forEach((child) => child.updateFromParent());
  61. },
  62. setHeight() {
  63. if (!this.data.fixed || !this.data.placeholder) {
  64. return;
  65. }
  66. wx.nextTick(() => {
  67. getRect(this, '.van-tabbar').then((res) => {
  68. this.setData({ height: res.height });
  69. });
  70. });
  71. },
  72. },
  73. });