vant的时间控件默认展示当天时间
<van-fieldreadonlyrequiredclickablelabel=“时间事项":value="mattertimeValue"placeholder=“选择时间":rules="[{required:true,trigger:‘onSubmit’,message:’请选择事项时间'}]"@click="showmattertime=true"/><van-popup v-model="showmattertime" round position="bottom"><van-datetime-pickerv-model=“currentDate"type="date"title=“选择年月日":min-date="minDate":max-date=“maxDate"@cancel="showmattertime=false"@confirm="mattertimeConfirm"/></van-popup>
data(){return{maxDate:new Date() // 不写具体的时间表示最大为当天minDate:new Date(1990,0,1)}}// 取当天时间,并将值绑定页面就会是当天的默认值getnewDate(){let nowdata=new Date();let year=nowdata.getFullYear();let month=nowdata.getMonth()+1;let date=nowdata.getDate();let nowtime=year+"-";if(month<10){nowtime+="0"};nowtime+=month+"-";if(date<10){nowtime+="0"};nowtime+=date;// this.mattertimeValue是组件:value绑定的值this.mattertimeValue=nowtime},// 时间下拉选择事件mattertimeConfirm(time){let nowdata=new Date();let year=nowdata.getFullYear();let month=nowdata.getMonth()+1;let date=nowdata.getDate();let clock=year+"-";if(month<10){clock+="0"};clock+=month+"-";if(date<10){clock+="0"};clock+=date;// this.mattertimeValue是组件:value绑定的值// this.showmattertime是组件@cancel和click和v-model绑定的值this.mattertimeValue=clock;this.showmattertime=false}