dblclick.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <template>
  2. <div class="dblclick_box" @dblclick="showInput">
  3. <div v-if="!isShowInput">
  4. <span>{{ callback }}</span>
  5. </div>
  6. <div v-else>
  7. <input v-model="callback" v-focus="isAutofocus" type="text" @blur="onblur" @keyup.enter="clickEnter">
  8. </div>
  9. </div>
  10. </template>
  11. <script>
  12. export default {
  13. name: 'Dblclick',
  14. directives: {
  15. focus: {
  16. inserted: function(el) {
  17. el.focus()
  18. }
  19. }
  20. },
  21. props: {
  22. content: String
  23. },
  24. data() {
  25. return {
  26. callback: this.content,
  27. isShowInput: false,
  28. isAutofocus: false
  29. }
  30. },
  31. watch: {
  32. content(val) {
  33. this.callback = val
  34. }
  35. },
  36. methods: {
  37. showInput() {
  38. this.isShowInput = true
  39. this.isAutofocus = true
  40. },
  41. onblur() {
  42. this.isShowInput = false
  43. this.isAutofocus = false
  44. this.callback = this.content
  45. },
  46. clickEnter() {
  47. this.isShowInput = false
  48. this.isAutofocus = false
  49. this.$emit('getInputData', this.callback)
  50. }
  51. }
  52. }
  53. </script>
  54. <style scoped>
  55. .dblclick_box {
  56. min-height: 30px;
  57. }
  58. </style>