项目开发发现,日历组件的值直接传到后端会报400,需要将时间格式化才行,话不多说直接上代码
<van-field
readonly
clickable
name="date"
:value="detailInfo.calendar"
label="日期"
placeholder="点击选择日期"
@click="showCalendar = true"
/>
<van-calendar v-model="showCalendar" @confirm="onConfirmCalendar" />
onConfirmCalendar(value,index){
let date = new Date(value)
let y = date.getFullYear()
let m = date.getMonth() + 1
m = m < 10 ? ('0' + m) : m
let d = date.getDate()
d = d < 10 ? ('0' + d) : d
const time = y + '-' + m + '-' + d;
console.log(time)//输出例:2021-06-23
this.detailInfo.calendar = time;
this.showCalendar = false;
}