DatePicker.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <div class="wrap">
  3. <DatePicker
  4. class="date-picker"
  5. :value="moment(value, 'YYYY-MM-DD')"
  6. @focus="onFocus"
  7. @change="onChange"
  8. @blur="onBlur"
  9. />
  10. <span>{{ reactData.tip }}</span>
  11. </div>
  12. </template>
  13. <script lang="ts">
  14. import { defineComponent, reactive, toRefs } from 'vue';
  15. import { DatePicker } from 'ant-design-vue';
  16. import moment from 'moment';
  17. const props = {
  18. value: { type: String, default: '' },
  19. tip: { type: String, default: '' },
  20. };
  21. export default defineComponent({
  22. components: { DatePicker },
  23. props,
  24. emits: ['change'],
  25. setup(props, { emit }) {
  26. const reactData = reactive({
  27. tip: '',
  28. });
  29. function onFocus() {
  30. reactData.tip = props.tip;
  31. }
  32. function onBlur() {
  33. reactData.tip = '';
  34. }
  35. function onChange(val) {
  36. emit('change', val);
  37. }
  38. return {
  39. onFocus,
  40. onBlur,
  41. onChange,
  42. reactData,
  43. moment,
  44. ...toRefs(props),
  45. };
  46. },
  47. });
  48. </script>
  49. <style scoped>
  50. .wrap {
  51. display: flex;
  52. }
  53. .date-picker {
  54. width: 55%;
  55. margin-right: 10px;
  56. }
  57. span {
  58. font-size: 13px;
  59. line-height: 250%;
  60. color: gray;
  61. }
  62. </style>