index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. "use strict";
  2. exports.__esModule = true;
  3. exports["default"] = void 0;
  4. var _utils = require("../utils");
  5. var _findParent = require("../mixins/find-parent");
  6. /* eslint-disable object-shorthand */
  7. var _use = (0, _utils.use)('tab'),
  8. sfc = _use[0],
  9. bem = _use[1];
  10. var _default = sfc({
  11. mixins: [_findParent.FindParentMixin],
  12. props: {
  13. title: String,
  14. disabled: Boolean
  15. },
  16. data: function data() {
  17. return {
  18. inited: false
  19. };
  20. },
  21. computed: {
  22. index: function index() {
  23. return this.parent.tabs.indexOf(this);
  24. },
  25. selected: function selected() {
  26. return this.index === this.parent.curActive;
  27. }
  28. },
  29. watch: {
  30. 'parent.curActive': function parentCurActive() {
  31. this.inited = this.inited || this.selected;
  32. },
  33. title: function title() {
  34. this.parent.setLine();
  35. }
  36. },
  37. created: function created() {
  38. this.findParent('van-tabs');
  39. },
  40. mounted: function mounted() {
  41. var tabs = this.parent.tabs;
  42. var index = this.parent.slots().indexOf(this.$vnode);
  43. tabs.splice(index === -1 ? tabs.length : index, 0, this);
  44. if (this.slots('title')) {
  45. this.parent.renderTitle(this.$refs.title, this.index);
  46. }
  47. },
  48. beforeDestroy: function beforeDestroy() {
  49. this.parent.tabs.splice(this.index, 1);
  50. },
  51. render: function render(h) {
  52. var slots = this.slots;
  53. var shouldRender = this.inited || !this.parent.lazyRender;
  54. return h("div", {
  55. "directives": [{
  56. name: "show",
  57. value: this.selected || this.parent.animated
  58. }],
  59. "class": bem('pane')
  60. }, [shouldRender ? slots() : h(), slots('title') && h("div", {
  61. "ref": "title"
  62. }, [slots('title')])]);
  63. }
  64. });
  65. exports["default"] = _default;