| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import { use } from '../utils';
- import Info from '../info';
- var _use = use('badge'),
- sfc = _use[0],
- bem = _use[1];
- export 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, {
- "attrs": {
- "info": this.info
- },
- "class": bem('info')
- })])]);
- }
- });
|