index.js 1.9 KB

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