zmc
2023-12-01 f4062e41dfbe26ca7664a963357cc0b9bea37b44
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!--月份选择器组件    
    默认选择上个月
 
  
  初始渲染时就将时间传递给父组件:
  ** 
  在父组件中设置
    <MonthSelect @submit-value="giveMonth"></MonthSelect>
   giveTime(val) {
        将中国标准时间转为指定格式(该组件返回的标准时间的格式,所以必须的加这个函数)
        this.month = dayjs(val).format('YYYY-MM-DD');
      },
  ***
-->
 
<script>
import dayjs from 'dayjs';
import time from '@/utils/time.js'
  export default {
    props:{
      month:{
         type:String,
        default:''
      }
    },
    emits:['submitValue'],
    
    data() {
      return{
        value:''
      }
    },
    watch:{
      month(){
        if(this.month!=''){
          this.value = this.month
        }
      }
    },
    mounted() {
        this.pre_month()
    },
    methods: {
        pre_month(){
          this.value = dayjs().subtract(1,'month').startOf('month').format('YYYY-MM-DD')
          this.$emit('submitValue',this.value)
        },
      judgeDateValid(date) {
          return time.judgeDateValid(date)
        }
     }
}
</script>
 
<template>
      <div class="block">
        <span class="demonstration">月份:</span>
        <el-date-picker
          v-model="value"
          type="month"
          placeholder="选择月份"
          :disabled-date="judgeDateValid"
          @change="$emit('submitValue',value)"
        />
      </div>
</template>
 
<style  scoped>
 
.demonstration {
  color: #333333;
  font-weight: bold;
  font-size: 14px;
}
</style>