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
| <template>
| <el-form-item label="时间">
| <el-date-picker
| :model-value="value"
| @change="handleChange"
| type="month"
| 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
| }
| },
| emits: ['update:value'],
| data() {
| return {};
| },
| 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.handleChange(new Date());
| }
| }
| };
| </script>
|
|