Vue2日期选择器插件(vue-datepicker-local)

参考文档: https://github.com/weifeiyue/vue-datepicker-local

支持年份选择器,月份选择器,日期选择器,时间选择器,且均支持范围选择

效果如下演示年月日选择(修改组件相关默认样式,并且只能选择当前时间往前50年之内的日期)

<DatePicker
	v-model="date"
	:local="local"
	placeholder="请选择注册时间"
	format="YYYY-MM-DD"
	:disabled-date="disabledDate"
	clearable />

import DatePicker from 'vue-datepicker-local'
components: {
	DatePicker
},
data () {
	return {
		date: new Date(), // 默认选择当前日期
		local: { // 定制化日期选择的格式内容
			dow: 1, // Monday is the first day of the week
			yearSuffix: '年', // format of head
			monthsHead: '1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月'.split('_'), // months of head
			months: '一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月'.split('_'), // months of panel
			weeks: '一_二_三_四_五_六_日'.split('_') // weeks
		},
	}
},
watch: {
	date (to, from) {
		console.log('to:', to)
		if (to === '') {
			this.checkFields('date')
		} else {
			this.checkFocus('date')
		}
	}
},
methods: {
	disabledDate (date) {
		if (date.getTime() > new Date().getTime()) { // 当前日期以后的时间禁用
			return true
		}
		// 当前时间50年前的日期禁用
		if (date.getFullYear() < new Date().getFullYear() - 50) {
			return true
		}
		if (date.getFullYear() === new Date().getFullYear() - 50 && date.getMonth() < new Date().getMonth()) {
			return true
		}
		if (date.getFullYear() === new Date().getFullYear() - 50 && date.getMonth() === new Date().getMonth() && date.getDate() < new Date().getDate()) {
			return true
		}
	}
}
// 重写组件相关样式
.datepicker {
	width: 290px;
	height: 40px;
	line-height: 40px;
	/deep/ input {
		color: #444;
		height: 40px;
		line-height: 40px;
	}
	/deep/ .focus {
		border: 1px solid @mainColor;
	}
	/deep/ .datepicker-popup {
		width: 278px;
		.calendar-head {
			width: 278px;
			.calendar-year-select, .calendar-month-select  {
				font-size: 14px;
				&:hover {
					color: @mainColor;
				}
			}
			.calendar-prev-year-btn, .calendar-prev-month-btn, .calendar-next-year-btn, .calendar-next-month-btn {
				&:hover {
					color: @mainColor;
				}
			}
		}
		.calendar-body {
			width: 278px;
			height: 200px;
			.calendar-date {
				line-height: 100%;
			}
			.calendar-date-selected {
				background: @mainColor;
			}
		}
		.datepicker__buttons {
			.datepicker__button-cancel {
				background: E3E3E3;
			}
			.datepicker__button-select {
				background: @mainColor;
			}
		}
	}
	.calendar-date-selected {
		background: @mainColor;
	}
}
  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
ant-design-vue3日期选择框可以通过DatePicker组件来实现。根据引用提供的信息,可以根据需求选择单天时间选择或多天时间段选择。对于单天时间选择,可以通过设置不同的限制条件来控制可选日期的范围,比如只能选明天及之后的日期、只能选今天及之后的日期、只能选昨天及之前的日期、或者只能选今天及之前的日期。对于多天时间段选择,可以选择周和月作为时间单位。根据引用和引用提供的配置示例,可以引入ant-design-vue组件和样式,并在需要的地方使用相关组件,如DatePicker组件。这样就可以在ant-design-vue3项目中使用日期选择框了。123 #### 引用[.reference_title] - *1* [ant-design-vueDatePicker 日期选择框(禁用部分时间和显示设置)](https://blog.csdn.net/pipizhou16/article/details/125502922)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}} ] [.reference_item] - *2* *3* [nuxt.js-ant-design-vue配置踩坑日记](https://blog.csdn.net/weixin_42232156/article/details/126140218)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}} ] [.reference_item] [ .reference_list ]
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值