index.js 942B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { VantComponent } from '../common/component';
  2. VantComponent({
  3. field: true,
  4. classes: ['node-class'],
  5. props: {
  6. checked: null,
  7. loading: Boolean,
  8. disabled: Boolean,
  9. activeColor: String,
  10. inactiveColor: String,
  11. size: {
  12. type: String,
  13. value: '30',
  14. },
  15. activeValue: {
  16. type: null,
  17. value: true,
  18. },
  19. inactiveValue: {
  20. type: null,
  21. value: false,
  22. },
  23. },
  24. methods: {
  25. onClick() {
  26. const { activeValue, inactiveValue, disabled, loading } = this.data;
  27. if (disabled || loading) {
  28. return;
  29. }
  30. const checked = this.data.checked === activeValue;
  31. const value = checked ? inactiveValue : activeValue;
  32. this.$emit('input', value);
  33. this.$emit('change', value);
  34. },
  35. },
  36. });