结合Cell 单元格,value值绑定显示的内容
结合popup弹出框,使用
<!--结束时间-->
<van-cell is-link title="结束时间" :value="value2" @click="showPopup2"/>
<van-popup v-model="show2" position="bottom" :style="{ height: '30%' }">
<van-datetime-picker
@confirm="confirm2"
@cancel="cancel2"
v-model="currentDate2"
type="datetime"
title="选择结束时间"
:min-date="minDate2"
:max-date="maxDate2">
</van-datetime-picker>
</van-popup>
<script>
export default {
data() {
return {
value2: ''//结束时间显示
show2: false,//弹出框是否显示
minDate2: new Date(),//结束时间
maxDate2: new Date(2035, 10, 1),//结束时间
currentDate2: new Date(),//结束时间
}
},
methods: {
//结束时间确定
confirm2() {
this.show2 = false;//弹出框隐藏
//拼接显示时间 年月日时分秒,toString().padStart(2, "0")这个是将1:1:0显示为01:01:00
this.value2 = this.currentDate2.getFullYear() + '-'
+ (this.currentDate2.getMonth() + 1).toString().padStart(2, "0") + '-'
+ this.currentDate2.getDate() + ' '
+ this.currentDate2.getHours().toString().padStart(2, "0") + ':'
+ this.currentDate2.getMinutes().toString().padStart(2, "0") + ':'
+ this.currentDate2.getSeconds().toString().padStart(2, "0")
},
//结束时间取消
cancel2() {
this.show2 = false;//弹出框隐藏
},
//结束时间弹出层
showPopup2() {
this.show2 = true;//弹出框显示
},
}
}
</script>