[improvement] Badge: add change event (#2017)

This commit is contained in:
neverland
2018-11-02 14:19:39 +08:00
committed by GitHub
parent 42f985cd7b
commit fc8937aa26
8 changed files with 92 additions and 27 deletions
+21 -4
View File
@@ -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);
}
}
});