index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. },
  13. data: {
  14. active: false
  15. },
  16. methods: {
  17. onClick() {
  18. if (this.parent) {
  19. this.parent.onChange(this);
  20. }
  21. this.$emit('click');
  22. },
  23. updateFromParent() {
  24. const { parent } = this;
  25. if (!parent) {
  26. return;
  27. }
  28. const index = parent.children.indexOf(this);
  29. const parentData = parent.data;
  30. const { data } = this;
  31. const active = (data.name || index) === parentData.active;
  32. const patch = {};
  33. if (active !== data.active) {
  34. patch.active = active;
  35. }
  36. if (parentData.activeColor !== data.activeColor) {
  37. patch.activeColor = parentData.activeColor;
  38. }
  39. if (parentData.inactiveColor !== data.inactiveColor) {
  40. patch.inactiveColor = parentData.inactiveColor;
  41. }
  42. return Object.keys(patch).length > 0
  43. ? this.set(patch)
  44. : Promise.resolve();
  45. }
  46. }
  47. });