riku
2024-06-07 0a97c702074830791cb29a158098f05c8033c4b1
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
<template>
  <!-- <el-form-item label="时间" :prop="prop"> -->
  <el-date-picker
    v-model="date"
    @change="handleChange"
    :type="type"
    placeholder="选择时间"
    size="small"
    style="width: 100px"
  />
  <!-- </el-form-item> -->
</template>
 
<script>
const MONTH = 'month'
 
export default {
  props: {
    type: {
      type: String,
      default: MONTH
    },
    // 返回结果
    modelValue: Date,
    // 是否默认返回初始选项
    initValue: {
      type: Boolean,
      default: true
    },
    prop: String
  },
  emits: ['update:modelValue'],
  data() {
    return {
      date: this.modelValue
    }
  },
  computed: {},
  methods: {
    handleChange(value) {
      this.$emit('update:modelValue', 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>