riku
2024-04-24 da51e7d5bbf5ff1610209510571e94d0523b515c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<template>
  <el-form-item label="时间" :prop="prop">
    <el-date-picker
      v-model="date"
      @change="handleChange"
      :type="type"
      placeholder="选择时间"
      style="width: 150px"
    />
  </el-form-item>
</template>
 
<script>
import dayjs from 'dayjs';
 
const MONTH = 'month';
 
export default {
  props: {
    type: {
      type: String,
      default: MONTH
    },
    // 返回结果
    value: Date,
    // 是否默认返回初始选项
    initValue: {
      type: Boolean,
      default: true
    },
    prop: String
  },
  emits: ['update:value'],
  data() {
    return {
      date: this.value
    };
  },
  computed:{
  },
  methods: {
    handleChange(value) {
      this.$emit('update:value', value);
    },
    timeFormat() {
      switch (this.type) {
        case MONTH:
          return 'YYYY-MM';
        default:
          return 'YYYY-MM';
      }
    }
  },
  mounted() {
    if (this.initValue) {
      this.date = new Date()
      this.handleChange(this.date);
    }
  }
};
</script>