index.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var component_1 = require("../common/component");
  4. var safe_area_1 = require("../mixins/safe-area");
  5. component_1.VantComponent({
  6. mixins: [safe_area_1.safeArea()],
  7. relation: {
  8. name: 'tabbar-item',
  9. type: 'descendant',
  10. linked: function (target) {
  11. this.children.push(target);
  12. target.parent = this;
  13. target.updateFromParent();
  14. },
  15. unlinked: function (target) {
  16. this.children = this.children.filter(function (item) { return item !== target; });
  17. this.updateChildren();
  18. }
  19. },
  20. props: {
  21. active: {
  22. type: [Number, String],
  23. observer: 'updateChildren'
  24. },
  25. activeColor: {
  26. type: String,
  27. observer: 'updateChildren'
  28. },
  29. inactiveColor: {
  30. type: String,
  31. observer: 'updateChildren'
  32. },
  33. fixed: {
  34. type: Boolean,
  35. value: true
  36. },
  37. border: {
  38. type: Boolean,
  39. value: true
  40. },
  41. zIndex: {
  42. type: Number,
  43. value: 1
  44. }
  45. },
  46. beforeCreate: function () {
  47. this.children = [];
  48. },
  49. methods: {
  50. updateChildren: function () {
  51. var children = this.children;
  52. if (!Array.isArray(children) || !children.length) {
  53. return Promise.resolve();
  54. }
  55. return Promise.all(children.map(function (child) { return child.updateFromParent(); }));
  56. },
  57. onChange: function (child) {
  58. var index = this.children.indexOf(child);
  59. var active = child.data.name || index;
  60. if (active !== this.data.active) {
  61. this.$emit('change', active);
  62. }
  63. }
  64. }
  65. });