index.js 1.4 KB

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