index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { VantComponent } from '../common/component';
  2. import { canIUseModel } from '../common/version';
  3. VantComponent({
  4. field: true,
  5. classes: ['field-class', 'input-class', 'cancel-class'],
  6. props: {
  7. value: {
  8. type: String,
  9. value: '',
  10. },
  11. label: String,
  12. focus: Boolean,
  13. error: Boolean,
  14. disabled: Boolean,
  15. readonly: Boolean,
  16. inputAlign: String,
  17. showAction: Boolean,
  18. useActionSlot: Boolean,
  19. useLeftIconSlot: Boolean,
  20. useRightIconSlot: Boolean,
  21. leftIcon: {
  22. type: String,
  23. value: 'search',
  24. },
  25. rightIcon: String,
  26. placeholder: String,
  27. placeholderStyle: String,
  28. actionText: {
  29. type: String,
  30. value: '取消',
  31. },
  32. background: {
  33. type: String,
  34. value: '#ffffff',
  35. },
  36. maxlength: {
  37. type: Number,
  38. value: -1,
  39. },
  40. shape: {
  41. type: String,
  42. value: 'square',
  43. },
  44. clearable: {
  45. type: Boolean,
  46. value: true,
  47. },
  48. clearTrigger: {
  49. type: String,
  50. value: 'focus',
  51. },
  52. clearIcon: {
  53. type: String,
  54. value: 'clear',
  55. },
  56. },
  57. methods: {
  58. onChange(event) {
  59. if (canIUseModel()) {
  60. this.setData({ value: event.detail });
  61. }
  62. this.$emit('change', event.detail);
  63. },
  64. onCancel() {
  65. /**
  66. * 修复修改输入框值时,输入框失焦和赋值同时触发,赋值失效
  67. * https://github.com/youzan/vant-weapp/issues/1768
  68. */
  69. setTimeout(() => {
  70. if (canIUseModel()) {
  71. this.setData({ value: '' });
  72. }
  73. this.$emit('cancel');
  74. this.$emit('change', '');
  75. }, 200);
  76. },
  77. onSearch(event) {
  78. this.$emit('search', event.detail);
  79. },
  80. onFocus(event) {
  81. this.$emit('focus', event.detail);
  82. },
  83. onBlur(event) {
  84. this.$emit('blur', event.detail);
  85. },
  86. onClear(event) {
  87. this.$emit('clear', event.detail);
  88. },
  89. onClickInput(event) {
  90. this.$emit('click-input', event.detail);
  91. },
  92. },
  93. });