index.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. useLeftIconSlot: Boolean,
  15. useRightIconSlot: Boolean,
  16. leftIcon: {
  17. type: String,
  18. value: 'search'
  19. },
  20. rightIcon: String,
  21. placeholder: String,
  22. placeholderStyle: String,
  23. actionText: {
  24. type: String,
  25. value: '取消'
  26. },
  27. background: {
  28. type: String,
  29. value: '#ffffff'
  30. },
  31. maxlength: {
  32. type: Number,
  33. value: -1
  34. },
  35. shape: {
  36. type: String,
  37. value: 'square'
  38. },
  39. clearable: {
  40. type: Boolean,
  41. value: true
  42. }
  43. },
  44. methods: {
  45. onChange(event) {
  46. this.setData({ value: event.detail });
  47. this.$emit('change', event.detail);
  48. },
  49. onCancel() {
  50. /**
  51. * 修复修改输入框值时,输入框失焦和赋值同时触发,赋值失效
  52. * https://github.com/youzan/@vant/weapp/issues/1768
  53. */
  54. setTimeout(() => {
  55. this.setData({ value: '' });
  56. this.$emit('cancel');
  57. this.$emit('change', '');
  58. }, 200);
  59. },
  60. onSearch() {
  61. this.$emit('search', this.data.value);
  62. },
  63. onFocus() {
  64. this.$emit('focus');
  65. },
  66. onBlur() {
  67. this.$emit('blur');
  68. },
  69. onClear() {
  70. this.$emit('clear');
  71. },
  72. }
  73. });