| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- "use strict";
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- exports.__esModule = true;
- exports["default"] = void 0;
- var _utils = require("../utils");
- var _info = _interopRequireDefault(require("../info"));
- var _use = (0, _utils.use)('badge'),
- sfc = _use[0],
- bem = _use[1];
- var _default = sfc({
- props: {
- url: String,
- info: [String, Number],
- title: String
- },
- inject: ['vanBadgeGroup'],
- created: function created() {
- this.parent.badges.push(this);
- },
- beforeDestroy: function beforeDestroy() {
- var _this = this;
- this.parent.badges = this.parent.badges.filter(function (item) {
- return item !== _this;
- });
- },
- computed: {
- parent: function parent() {
- if (process.env.NODE_ENV !== 'production' && !this.vanBadgeGroup) {
- console.error('[Vant] Badge needs to be child of BadgeGroup');
- }
- return this.vanBadgeGroup;
- },
- select: function select() {
- return this.parent.badges.indexOf(this) === +this.parent.activeKey;
- }
- },
- methods: {
- onClick: function onClick() {
- var index = this.parent.badges.indexOf(this);
- this.$emit('click', index);
- this.parent.$emit('change', index);
- }
- },
- render: function render(h) {
- return h("a", {
- "attrs": {
- "href": this.url
- },
- "class": [bem({
- select: this.select
- }), 'van-hairline'],
- "on": {
- "click": this.onClick
- }
- }, [h("div", {
- "class": bem('text')
- }, [this.title, h(_info["default"], {
- "attrs": {
- "info": this.info
- },
- "class": bem('info')
- })])]);
- }
- });
- exports["default"] = _default;
|