input.vue 747 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <template>
  2. <el-input
  3. @keyup.enter.native="onUpdate"
  4. v-model="value"
  5. @blur="onUpdate"
  6. v-bind="$attrs"
  7. >
  8. <template slot="suffix">
  9. <slot name="suffix"></slot>
  10. </template>
  11. </el-input>
  12. </template>
  13. <script>
  14. export default {
  15. props: ['val', 'onChange'],
  16. data() {
  17. return {
  18. value: '',
  19. oldValue: ''
  20. };
  21. },
  22. methods: {
  23. onUpdate(e) {
  24. const { value } = e.target;
  25. if (value !== this.oldValue) {
  26. this.oldValue = value;
  27. this.$emit('change', value);
  28. }
  29. }
  30. },
  31. watch: {
  32. val: {
  33. immediate: true,
  34. handler(value) {
  35. this.value = value;
  36. if (!this.oldValue) {
  37. this.oldValue = value;
  38. }
  39. }
  40. }
  41. }
  42. };
  43. </script>