index.js 726 B

123456789101112131415161718192021222324252627282930
  1. import { VantComponent } from '../common/component';
  2. VantComponent({
  3. relation: {
  4. type: 'ancestor',
  5. name: 'badge-group',
  6. linked(target) {
  7. this.parent = target;
  8. }
  9. },
  10. props: {
  11. info: null,
  12. title: String
  13. },
  14. methods: {
  15. onClick() {
  16. const { parent } = this;
  17. if (!parent) {
  18. return;
  19. }
  20. const index = parent.badges.indexOf(this);
  21. parent.setActive(index).then(() => {
  22. this.$emit('click', index);
  23. parent.$emit('change', index);
  24. });
  25. },
  26. setActive(active) {
  27. return this.set({ active });
  28. }
  29. }
  30. });