本文實例為大家分享了vant時間控件的使用方法,供大家參考,具體內(nèi)容如下
代碼:
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
< template > < div class = "shoukuan" > <!-- 頭部公共搜索框 --> < tabbar title = "添加團隊活動" ></ tabbar > < div class = "con" > < van-cell-group > < van-field v-model = "name" clearable label = "活動名稱" placeholder = "請選擇活動名稱" /> < van-field v-model = "starttime" clearable label = "開始時間" placeholder = "請輸入開始時間" @ focus = "start" /> < van-field v-model = "endtime" clearable label = "結(jié)束時間" placeholder = "請輸入結(jié)束時間" @ focus = "end" /> </ van-cell-group > < van-cell-group > < van-field v-model = "message" rows = "2" autosize label = "活動詳情" type = "textarea" maxlength = "50" placeholder = "請輸入" show-word-limit /> </ van-cell-group > </ div > < van-button type = "primary" size = "large" @ click = "add" >確認(rèn)添加</ van-button > <!-- 開始時間控件 --> < van-popup v-model = "show" position = "bottom" > < van-datetime-picker v-model = "currentDate" type = "datetime" :min-date = "minDate" :max-date = "maxDate" @ confirm = "confirm" @ cancel = "cancel" :formatter = "formatter" /> </ van-popup > <!-- 結(jié)束時間控件 --> < van-popup v-model = "show1" position = "bottom" > < van-datetime-picker v-model = "currentDate1" type = "datetime" :min-date = "minDate" :max-date = "maxDate" @ confirm = "confirm1" @ cancel = "cancel1" :formatter = "formatter" /> </ van-popup > </ div > </ template > < script > import tabbar from "../../components/navbar"; export default { data() { return { name: "", //活動名稱 message: "", //活動詳情 show: false, //開始時間彈窗 show1: false, //結(jié)束時間彈窗 minHour: 10, maxHour: 20, minDate: new Date(), maxDate: new Date(2020, 11, 31), currentDate: new Date(), //開始標(biāo)準(zhǔn)時間 currentDate1: new Date(), //結(jié)束標(biāo)準(zhǔn)時間 starttime: "", //開始時間 starttime1: "", //開始時間時間戳 endtime: "", //結(jié)束時間 endtime1: "" //結(jié)束時間時間戳 }; }, components: { tabbar }, mounted() {}, methods: { // 選擇開始時間 start() { this.show = true; }, // 選擇結(jié)束時間 end() { this.show1 = true; }, // 點擊確定 confirm() { this.show = false; this.starttime = this.currentDate.getFullYear() + "年" + (Number(this.currentDate.getMonth()) + 1) + "月" + this.currentDate.getDate() + "日 " + this.currentDate.getHours() + ":" + this.currentDate.getMinutes(); this.starttime1 = new Date(this.currentDate).getTime() / 1000; }, // 點擊取消 cancel() { this.show = false; }, confirm1() { this.show1 = false; this.endtime = this.currentDate1.getFullYear() + "年" + (Number(this.currentDate1.getMonth()) + 1) + "月" + this.currentDate1.getDate() + "日 " + this.currentDate1.getHours() + ":" + this.currentDate1.getMinutes(); this.endtime1 = new Date(this.currentDate1).getTime() / 1000; }, cancel1() { this.show1 = false; }, // 處理控件顯示的時間格式 formatter(type, value) { // 格式化選擇器日期 if (type === "year") { return `${value}年`; } else if (type === "month") { return `${value}月`; } else if (type === "day") { return `${value}日`; } else if (type === "hour") { return `${value}時`; } else if (type === "minute") { return `${value}分`; } return value; }, // 點擊添加按鈕 add() { if ( !this.name.trim() || !this.starttime.trim() || !this.starttime.trim() || !this.message.trim() ) { this.$toast("請輸入完整的活動信息"); } else { this.axios .post("/api/agent_team/addTeamActivity", { activity_name: this.name, activity_content: this.message, start_time: this.starttime1, end_time: this.endtime1 }) .then(data => { this.$toast("添加活動成功"); setTimeout(() => { this.$router.go(-1); }, 1000); }); } } } }; </ script > < style lang = "less" scoped> .shoukuan { padding-top: 44px; .van-button--large { width: 92%; margin-left: 4%; margin-top: 25%; } } </ style > |
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。
原文鏈接:https://blog.csdn.net/weixin_43848576/article/details/102697266