index.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { VantComponent } from '../common/component';
  2. VantComponent({
  3. relation: {
  4. name: 'tabbar-item',
  5. type: 'descendant',
  6. current: 'tabbar',
  7. linked(target) {
  8. target.parent = this;
  9. target.updateFromParent();
  10. },
  11. unlinked() {
  12. this.updateChildren();
  13. },
  14. },
  15. props: {
  16. active: {
  17. type: null,
  18. observer: 'updateChildren',
  19. },
  20. activeColor: {
  21. type: String,
  22. observer: 'updateChildren',
  23. },
  24. inactiveColor: {
  25. type: String,
  26. observer: 'updateChildren',
  27. },
  28. fixed: {
  29. type: Boolean,
  30. value: true,
  31. },
  32. border: {
  33. type: Boolean,
  34. value: true,
  35. },
  36. zIndex: {
  37. type: Number,
  38. value: 1,
  39. },
  40. safeAreaInsetBottom: {
  41. type: Boolean,
  42. value: true,
  43. },
  44. },
  45. methods: {
  46. updateChildren() {
  47. const { children } = this;
  48. if (!Array.isArray(children) || !children.length) {
  49. return Promise.resolve();
  50. }
  51. return Promise.all(children.map((child) => child.updateFromParent()));
  52. },
  53. onChange(child) {
  54. const index = this.children.indexOf(child);
  55. const active = child.data.name || index;
  56. if (active !== this.data.active) {
  57. this.$emit('change', active);
  58. }
  59. },
  60. },
  61. });