1. 程式人生 > 其它 >Warning: [antdv: DatePicker] `value` provides invalidate moment time. If you want to set empty value、或TimePicker 時間選擇框報waring

Warning: [antdv: DatePicker] `value` provides invalidate moment time. If you want to set empty value、或TimePicker 時間選擇框報waring

a-date-picker/a-time-picker繫結的時間變數是一個string型別,而ant design vue datepicker 預設需要moment格式,所以會報錯。

 1                         <a-col :xs="24" :md="12" :sm="24" :lg='16' :xl='6'>
 2                             <a-form-item label="時間">
 3                                 <a-date-picker
 4                                     v-model
="pickerDate" 5 @change="onChange" 6 style="margin-right: 5px;" 7 /> 8 <a-time-picker 9 v-model="picker" 10 format
="HH:mm" 11 @change="onPicker" 12 placeholder="時間" 13 /> 14 ~ 15 <a-time-picker 16 v-model="picker1"
17 @change="onPicker1" 18 format="HH:mm" 19 placeholder="時間" 20 /> 21 </a-form-item> 22 </a-col>

Js

 1 import moment from 'moment'
 2 export default {
 3     
 4     data(){
 5             // pickerl:' '不可為字串切記
 6             picker: moment('00:00', 'HH:mm'), //預設值
 7             picker1: moment(new Date(), 'HH:mm'), //預設值
 8             pickerDate: moment(new Date(), 'YYYY-MM-DD'), //預設值
 9     } ,
10     methods:{
11         moment,
12     }
13 }