index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { VantComponent } from '../common/component';
  2. VantComponent({
  3. props: {
  4. info: null,
  5. name: null,
  6. icon: String,
  7. dot: Boolean,
  8. },
  9. relation: {
  10. name: 'tabbar',
  11. type: 'ancestor',
  12. current: 'tabbar-item',
  13. },
  14. data: {
  15. active: false,
  16. },
  17. methods: {
  18. onClick() {
  19. if (this.parent) {
  20. this.parent.onChange(this);
  21. }
  22. this.$emit('click');
  23. },
  24. updateFromParent() {
  25. const { parent } = this;
  26. if (!parent) {
  27. return;
  28. }
  29. const index = parent.children.indexOf(this);
  30. const parentData = parent.data;
  31. const { data } = this;
  32. const active = (data.name || index) === parentData.active;
  33. const patch = {};
  34. if (active !== data.active) {
  35. patch.active = active;
  36. }
  37. if (parentData.activeColor !== data.activeColor) {
  38. patch.activeColor = parentData.activeColor;
  39. }
  40. if (parentData.inactiveColor !== data.inactiveColor) {
  41. patch.inactiveColor = parentData.inactiveColor;
  42. }
  43. return Object.keys(patch).length > 0
  44. ? this.set(patch)
  45. : Promise.resolve();
  46. },
  47. },
  48. });