IInput.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <a-input
  3. :addon-after="addonAfter"
  4. :addon-before="addonBefore"
  5. :default-value="defaultValue"
  6. :disabled="disabled"
  7. :id="id"
  8. :max-length="maxLength"
  9. :prefix="prefix"
  10. :size="size"
  11. :suffix="suffix || lenSuffix"
  12. :type="type"
  13. :allow-clear="allowClear"
  14. v-model="sValue"
  15. :value="value"
  16. @change="onChange"
  17. @input="onInput"
  18. @pressEnter="onPressEnter"
  19. @keydown="onKeydown"
  20. >
  21. <template :slot="slot" v-for="slot in Object.keys($slots)">
  22. <slot :name="slot"></slot>
  23. </template>
  24. </a-input>
  25. </template>
  26. <script>
  27. export default {
  28. name: 'IInput',
  29. model: {
  30. prop: 'value',
  31. event: 'change.value'
  32. },
  33. props: ['addonAfter', 'addonBefore', 'defaultValue', 'disabled', 'id', 'maxLength', 'prefix', 'size', 'suffix', 'type', 'value', 'allowClear'],
  34. data() {
  35. return {
  36. sValue: this.value || this.defaultValue || ''
  37. }
  38. },
  39. watch: {
  40. value(val) {
  41. this.sValue = val
  42. }
  43. },
  44. computed: {
  45. lenSuffix() {
  46. return this.maxLength && `${(this.sValue + '').length}/${this.maxLength}`
  47. }
  48. },
  49. methods: {
  50. onChange(e) {
  51. this.$emit('change', e)
  52. this.$emit('change.value', e.target.value)
  53. },
  54. onInput(e) {
  55. this.$emit('input', e)
  56. },
  57. onPressEnter(e) {
  58. this.$emit('pressEnter', e)
  59. },
  60. onKeydown(e) {
  61. this.$emit('keydown', e)
  62. }
  63. }
  64. }
  65. </script>