index.js 1.4 KB

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