index.js 1.8KB

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