uniapp implements birth date/time selection effect

 uniapp official website about date picker: picker | uni-app official website

 van-cell is a component in vant

 <!-- 出生日期 -->
<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange" 	v-show="isShow">
	<van-cell is-link title="出生日期"  mode="date" :value="date" :start="startDate" :end="endDate" />
</picker>

  If you don't use the vant component, you can write it like this

<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
	<view class="uni-input">{
   
   {date}}</view>
</picker>
<script>
	//出生日期
	function getDate(type) {
		const date = new Date();
	 
		let year = date.getFullYear();
		let month = date.getMonth() + 1;
		let day = date.getDate();
	 
		if (type === 'start') {
			year = year - 10;
		} else if (type === 'end') {
			year = year + 10;
		}
		month = month > 9 ? month : '0' + month;
		day = day > 9 ? day : '0' + day;
	 
		return `${year}-${month}-${day}`;
	}
	export default {
		data() {
			return {
                //出生日期
				date: getDate({
								format: true
							}),
				startDate: getDate('start'),
				endDate: getDate('end'),
			};
		},
		methods: {
			//出生日期
			bindDateChange: function(e) {
				this.date = e.detail.value;
			}
		},
	};
</script>

 

Guess you like

Origin blog.csdn.net/weixin_57607714/article/details/124323601