index.js 1.3KB

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