index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import { createNamespace } from '../utils';
  3. import { ChildrenMixin } from '../mixins/relation';
  4. import { route, routeProps } from '../utils/router';
  5. import Info from '../info';
  6. var _createNamespace = createNamespace('sidebar-item'),
  7. createComponent = _createNamespace[0],
  8. bem = _createNamespace[1];
  9. export default createComponent({
  10. mixins: [ChildrenMixin('vanSidebar')],
  11. props: _extends({}, routeProps, {
  12. dot: Boolean,
  13. // @deprecated
  14. info: [Number, String],
  15. badge: [Number, String],
  16. title: String,
  17. disabled: Boolean
  18. }),
  19. computed: {
  20. select: function select() {
  21. return this.index === +this.parent.activeKey;
  22. }
  23. },
  24. methods: {
  25. onClick: function onClick() {
  26. if (this.disabled) {
  27. return;
  28. }
  29. this.$emit('click', this.index);
  30. this.parent.$emit('input', this.index);
  31. this.parent.setIndex(this.index);
  32. route(this.$router, this);
  33. }
  34. },
  35. render: function render() {
  36. var _this$slots, _this$badge;
  37. var h = arguments[0];
  38. if (process.env.NODE_ENV === 'development' && this.info) {
  39. console.warn('[Vant] SidebarItem: "info" prop is deprecated, use "badge" prop instead.');
  40. }
  41. return h("a", {
  42. "class": bem({
  43. select: this.select,
  44. disabled: this.disabled
  45. }),
  46. "on": {
  47. "click": this.onClick
  48. }
  49. }, [h("div", {
  50. "class": bem('text')
  51. }, [(_this$slots = this.slots('title')) != null ? _this$slots : this.title, h(Info, {
  52. "attrs": {
  53. "dot": this.dot,
  54. "info": (_this$badge = this.badge) != null ? _this$badge : this.info
  55. },
  56. "class": bem('info')
  57. })])]);
  58. }
  59. });