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