field-radio.ts 605 B

123456789101112131415161718192021222324
  1. // module/user/components/field-radio/field-radio.ts
  2. Component({
  3. behaviors: ['wx://form-field'],
  4. lifetimes: {},
  5. properties: {
  6. name: { type: String },
  7. value: { type: String },
  8. defaultValue: { type: String },
  9. options: { type: Array, value: [] },
  10. },
  11. data: {},
  12. observers: {
  13. 'defaultValue'(value) {
  14. setTimeout(() => { if (!this.data.value) this.setData({ value }); }, 1000)
  15. }
  16. },
  17. methods: {
  18. onChange(event: { detail: { value: any } }) {
  19. const value = event.detail.value;
  20. this.setData({ value });
  21. this.triggerEvent('change', value)
  22. }
  23. }
  24. })