之前以为使用 disabledDate 限定日期就够了,后面说需要限制在此刻之前更严谨。这里就需要更改selectableRange的值。
刚开始想使用事件监听的方式,比如 change、focus 事件,但是发现不能,这里的事件是针对输入框的,而不是弹出来的 date-picker里面的输入选择框。所以使用监听他的值。
当我们日期每次变动的时候都需要去验证是否是当前日期,然后才看是否修改selectableRange的值
template 部分
<el-date-picker
placeholder="选择日期时间"
type="datetime"
value-format="yyyy-MM-dd HH:mm:ss"
:picker-options="options"
v-model="ruleForm.time"
style="width:100%"></el-date-picker>
script 部分
data() {
return {
ruleForm: {
time: ''
options: {
// 时间不能大于当前时间
disabledDate: time => {
return time.getTime() > Date.now()
selectableRange: '00:00:00 - 23:59:59'
watch: {
'ruleForm.time'(selectTime) {
const date = new Date(new Date(selectTime).setHours(0, 0, 0, 0)).getTime()
const today = new Date(new Date().setHours(0, 0, 0, 0)).getTime()
const curTime = new Date()
if (date >= today) {
// 当选择的日期就是当天的时候,这个时候就要限制时间应当小于此时此刻的时分秒
this.options.selectableRange = `'00:00:00 - ${String(curTime.getHours()).padStart(2, '0')}:
${String(curTime.getMinutes()).padStart(2, '0')}:${String(curTime.getSeconds()).padStart(2, '0')}`
} else {
// 当选择的日期小于当天的时候,这时需要把时分秒的限制放开,否则不能选择
this.options.selectableRange = '00:00:00 - 23:59:59'
之前以为使用disabledDate 限定日期就够了,后面说需要限制在此刻之前更严谨。这里就需要更改selectableRange的值。刚开始想使用事件监听的方式,比如 change、focus事件,但是发现不能,这里的事件是针对输入框的,而不是弹出来的 date-picker里面的输入选择框。所以使用监听他的值。当我们日期每次变动的时候都需要去验证是否是当前日期,然后才看是否修改selectableRange的值template 部分<el-date-picker plac..
时间
日期
选择器限制到某天的
时分秒
需求: 限制
时间
只能选择今天以及今天之后,
时分秒
也只能是
当前
时间
之后。
例如:2021:08:12 15:16:59 那选择
时间
的时候只能选择这个
时间
后的
时间
提示:图片中红色部分都是过
当前
时间
就
不能
选了。
<
el
-
date
-
picker
@focus='
date
Picker
Focus()'
v-mod
el
="startTime"
type="
date
time"
:
picker
-options="
picker
Options"
<
el
-
date
-
picker
v-mod
el
="ruleForm.monitorTime " format="yyyy-MM-dd HH:mm" style="width:100%"
value-format="yyyy-MM-dd HH:mm:ss" type="
date
time" :
picker
-options="
picker
Options"
placeholder="选择
日期
">
</
el
-
date
-
picker
>
picker
Options: {
//情况1 原创版权声明:本文为weixin_40998880原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
//本文链接:https://blog.csdn.net/weixin_40998880/article/details/106272897
//html
<
el
-
date
-
picker
v-mod
el
="time"
typ...
:placeholder="$t('time.endTime')"
value-format="yyyy-MM-dd"
:
picker
-options="
picker
Options"
data() {
return {
picker
Options: {
disabled
Date
: (time) => {
return time.getTime() < n
el
-
Date
Picker
禁选指定
日期
在项目中我们需要
日期
控件禁用一个指定
日期
之前的
时间
,这个
时间
点是一个变量时,我们应该怎么做呢?在这里用到的是vue的写法。
<
el
-
date
-
picker
v-mod
el
="scope.row.interview
Date
"
:clearable="false"
:
picker
-options="
picker
Options"
:editable="false"
value-format="yyyy-MM-dd"
不需要moment.js
tl;博士
通过执行npm install @wojtekmaj/react-
date
range-
picker
或yarn add @wojtekmaj/react-
date
range-
picker
。
通过添加import
Date
Range
Picker
from '@wojtekmaj/react-
date
range-
picker
'来import
Date
Range
Picker
from '@wojtekmaj/react-
date
range-
picker
' 。
通过添加<
Date
Range
Picker
> 。 使用onChange道具获取新值。
可以在sample目录中找到一个最小的演示页面。
寻找
时间
选择器或
日期
时间
import Vue from 'vue';
import
El
ementUI from '
el
ement-ui';
import '
el
ement-ui/lib/theme-chalk/index.css';
import App from './App.vue';
Vue.use(
El
ementUI);
new Vue({
el
: '#app',
render:
el
-
date
-
picker
是一款常见的
日期
选择器组件,而要求它
不能
小于
当前
日期
时间
且要
精确
到
时分秒
,则需要在组件的相应属性和方法上进行配置。
首先,可以通过给
el
-
date
-
picker
组件设置属性type为"
date
time"来实现选择
日期
和
时间
的功能。接着,可以设置属性value为
当前
日期
时间
,例如可以使用
Date
对象获取
当前
日期
时间
,再将其格式化为需要的格式,最后赋值给value属性。
除此之外,需要使用组件的方法来判断选择器的值是否小于
当前
日期
时间
。可以通过监听事件change,在事件处理函数中对选择器的值进行比较,如果小于
当前
日期
时间
,则将选择器的值设置为
当前
日期
时间
。
需要注意的是,为了实现
精确
到
时分秒
,需要在设置value属性和进行比较时均使用带有
时分秒
的
日期
时间
格式。
以上是一种实现
el
-
date
-
picker
不能
小于
当前
日期
时间
且
精确
到
时分秒
的方法,具体操作可以根据实际需求进行调整和优化。
has been blocked by CORS policy: Request header field secret is not allowed by Access-Control-Allow-
18917
每日一题(十)function showCase(value){ switch(value){ case 'A': console.log('case
m0_67135068:
echarts dataZoom 基本用法,给 yAxis 增加滚动条
软件园的肖邦:
error: src refspec master does not match any error:failed to push some refs to 'git@github.com:xxxx
pointer *:
webstorm报错cliEngineCtor is not a constructor this.options.parse is not a function at ESLintPlugin
cezxktguml:
echarts 饼图鼠标移上去不放大突出
bjyx_10050805:
webstorm报错cliEngineCtor is not a constructor this.options.parse is not a function at ESLintPlugin
前端项目中代码格式化配置:eslint + prettier + stylelint + pre-commit
vue3 element-plus el-dialog 二次封装,多层调用