van-datetime-picker组件---JS中国标准时间转化为年月日

例子

 <!-- 生日选择器 -->
 <van-popup v-model="showBirthdayPicker" position="bottom">
   <van-datetime-picker
     v-model="birthdatDate"
     type="date"
     @confirm="onConfirmBirthday"
     @cancel="showBirthdayPicker = false"
   />
 </van-popup>
export default {
    
    
  data() {
    
    
    return {
    
    
      birthdatDate: null,
	  showBirthdayPicker: false,
	  form: {
    
    
	    birthday: ''
	  }
    }
  }
}
 onConfirmBirthday (e) {
    
    
   this.showBirthdayPicker = false
   var time = e.getFullYear() + '-' + this.handleDate(e.getMonth() + 1) + '-' + this.handleDate(e.getDate())
   this.form.birthday = time
 },
 handleDate(val) {
    
    
   return val < 10 ? '0' + val : val
 },

效果图

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42554191/article/details/126394337