index.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { VantComponent } from '../common/component';
  2. VantComponent({
  3. field: true,
  4. classes: ['field-class', 'input-class', 'cancel-class'],
  5. props: {
  6. label: String,
  7. focus: Boolean,
  8. error: Boolean,
  9. disabled: Boolean,
  10. readonly: Boolean,
  11. inputAlign: String,
  12. showAction: Boolean,
  13. useActionSlot: Boolean,
  14. placeholder: String,
  15. placeholderStyle: String,
  16. background: {
  17. type: String,
  18. value: '#ffffff'
  19. },
  20. maxlength: {
  21. type: Number,
  22. value: -1
  23. },
  24. shape: {
  25. type: String,
  26. value: 'square'
  27. },
  28. clearable: {
  29. type: Boolean,
  30. value: true
  31. }
  32. },
  33. methods: {
  34. onChange(event) {
  35. this.set({ value: event.detail });
  36. this.$emit('change', event.detail);
  37. },
  38. onCancel() {
  39. /**
  40. * 修复修改输入框值时,输入框失焦和赋值同时触发,赋值失效
  41. * // https://github.com/youzan/vant-weapp/issues/1768
  42. */
  43. setTimeout(() => {
  44. this.set({ value: '' });
  45. this.$emit('cancel');
  46. this.$emit('change', '');
  47. }, 200);
  48. },
  49. onSearch() {
  50. this.$emit('search', this.data.value);
  51. },
  52. onFocus() {
  53. this.$emit('focus');
  54. },
  55. onBlur() {
  56. this.$emit('blur');
  57. },
  58. onClear() {
  59. this.$emit('clear');
  60. },
  61. }
  62. });