index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. exports.__esModule = true;
  4. exports["default"] = void 0;
  5. var _utils = require("../utils");
  6. var _info = _interopRequireDefault(require("../info"));
  7. var _use = (0, _utils.use)('badge'),
  8. sfc = _use[0],
  9. bem = _use[1];
  10. var _default = sfc({
  11. props: {
  12. url: String,
  13. info: [String, Number],
  14. title: String
  15. },
  16. inject: ['vanBadgeGroup'],
  17. created: function created() {
  18. this.parent.badges.push(this);
  19. },
  20. beforeDestroy: function beforeDestroy() {
  21. var _this = this;
  22. this.parent.badges = this.parent.badges.filter(function (item) {
  23. return item !== _this;
  24. });
  25. },
  26. computed: {
  27. parent: function parent() {
  28. if (process.env.NODE_ENV !== 'production' && !this.vanBadgeGroup) {
  29. console.error('[Vant] Badge needs to be child of BadgeGroup');
  30. }
  31. return this.vanBadgeGroup;
  32. },
  33. select: function select() {
  34. return this.parent.badges.indexOf(this) === +this.parent.activeKey;
  35. }
  36. },
  37. methods: {
  38. onClick: function onClick() {
  39. var index = this.parent.badges.indexOf(this);
  40. this.$emit('click', index);
  41. this.parent.$emit('change', index);
  42. }
  43. },
  44. render: function render(h) {
  45. return h("a", {
  46. "attrs": {
  47. "href": this.url
  48. },
  49. "class": [bem({
  50. select: this.select
  51. }), 'van-hairline'],
  52. "on": {
  53. "click": this.onClick
  54. }
  55. }, [h("div", {
  56. "class": bem('text')
  57. }, [this.title, h(_info["default"], {
  58. "attrs": {
  59. "info": this.info
  60. },
  61. "class": bem('info')
  62. })])]);
  63. }
  64. });
  65. exports["default"] = _default;