当前位置:   article > 正文

VUE-ElementUI 时间区间选择器_eleme ui daterange value 切割

eleme ui daterange value 切割

 

官方文档中使用picker-options属性来限制可选择的日期

一,单个输入框

  1. <el-date-picker
  2. v-model="value1"
  3. type="date"
  4. placeholder="选择日期"
  5. :picker-options="pickerOptions0">
  6. </el-date-picker>

设置选择今天以及今天之后的日期 

  1. data (){
  2. return {
  3. pickerOptions0: {
  4. disabledDate(time) {
  5. return time.getTime() < Date.now() - 8.64e7;
  6. }
  7. },
  8. }
  9. }

设置选择今天以及今天以前的日期

  1. data (){
  2. return {
  3. pickerOptions0: {
  4. disabledDate(time) {
  5. return time.getTime() > Date.now() - 8.64e6
  6. }
  7. },
  8. }
  9. }

设置选择今天之后的日期(不能选择当天时间)

  1. data (){
  2. return {
  3. pickerOptions0: {
  4. disabledDate(time) {
  5. return time.getTime() < Date.now();
  6. }
  7. },
  8. }
  9. }

设置选择今天之前的日期(不能选择当天)

  1. data (){
  2. return {
  3. pickerOptions0: {
  4. disabledDate(time) {
  5. return time.getTime() > Date.now();
  6. }
  7. },
  8. }
  9. }

 设置选择三个月之前到今天的日期

  1. data (){
  2. return {
  3. pickerOptions0: {
  4. disabledDate(time) {
  5. let curDate = (new Date()).getTime();
  6. let three = 90 * 24 * 3600 * 1000;
  7. let threeMonths = curDate - three;
  8. return time.getTime() > Date.now() || time.getTime() < threeMonths;;
  9. }
  10. },
  11. }
  12. }

二,两个输入框

  1. <el-date-picker
  2. v-model="value1"
  3. type="date"
  4. placeholder="开始日期"
  5. :picker-options="pickerOptions0">
  6. </el-date-picker>
  7. <el-date-picker
  8. v-model="value2"
  9. type="date"
  10. placeholder="结束日期"
  11. :picker-options="pickerOptions1">
  12. </el-date-picker>

限制结束日期不能大于开始日期

  1. data(){
  2. return {
  3. pickerOptions0: {
  4. disabledDate: (time) => {
  5. if (this.value2 != "") {
  6. return time.getTime() > Date.now() || time.getTime() > this.value2;
  7. } else {
  8. return time.getTime() > Date.now();
  9. }
  10. }
  11. },
  12. pickerOptions1: {
  13. disabledDate: (time) => {
  14. return time.getTime() < this.value1 || time.getTime() > Date.now();
  15. }
  16. },
  17. }
  18. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/390651
推荐阅读