[improvement] Badge: add change event (#2017)
This commit is contained in:
@@ -26,19 +26,36 @@ export default create({
|
||||
title: String
|
||||
},
|
||||
|
||||
beforeCreate() {
|
||||
this.$parent.badges.push(this);
|
||||
inject: ['vanBadgeGroup'],
|
||||
|
||||
created() {
|
||||
this.parent.badges.push(this);
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
this.parent.badges = this.parent.badges.filter(item => item !== this);
|
||||
},
|
||||
|
||||
computed: {
|
||||
parent() {
|
||||
if (process.env.NODE_ENV !== 'production' && !this.vanBadgeGroup) {
|
||||
console.error('[Vant] Badge needs to be child of BadgeGroup');
|
||||
}
|
||||
return this.vanBadgeGroup;
|
||||
},
|
||||
|
||||
select() {
|
||||
return this.$parent.badges.indexOf(this) === this.$parent.activeKey;
|
||||
return (
|
||||
this.parent.badges.indexOf(this) === +this.parent.activeKey
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
onClick() {
|
||||
this.$emit('click', this.$parent.badges.indexOf(this));
|
||||
const index = this.parent.badges.indexOf(this);
|
||||
this.$emit('click', index);
|
||||
this.parent.$emit('change', index);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user