Use Element+vue to implement start and end time limits

Use Element+vue to implement start and end time limits

This article example shares the specific code for using Element+vue to implement start and end time limits for your reference. The specific content is as follows

Effect

<el-form-item label="Start time">
   <el-date-picker v-model="startDate" type="datetime" placeholder="Select a date"
                   format="yyyy-MM-dd HH:mm:ss"
                   value-format="timestamp"
                   :editable="false"
                   :picker-options="pickerOptionsStart" @change="changeStart">
   </el-date-picker>
</el-form-item>
<el-form-item label="End time">
   <el-date-picker v-model="endDate" type="datetime" placeholder="Select a date"
                   style="width: 100%;"
                   format="yyyy-MM-dd HH:mm:ss"
                   value-format="timestamp"
                   :clearable="true"
                   :editable="false"
                   :picker-options="pickerOptionsEnd" @change="changeEnd">
   </el-date-picker>

</el-form-item>
pickerOptionsStart: {},
pickerOptionsEnd: {},
startDate: '',
endDate: '',

 changeStart() { // Limit the start time if (this.endDate != '') {
          if (this.endDate <= this.startDate) {
            this.$message.warning('End time must be greater than start time!');
            this.startDate = '';
          }
        }
        this.pickerOptionsEnd = Object.assign({}, this.pickerOptionsEnd, {
          disabledDate: (time) => {
            if (this.startDate) {
              return time.getTime() < this.startDate;
            }
          },
        });
      },

      changeEnd() { // Limit end time console.log(this.endDate);
        if (this.startDate != '') {
          if (this.endDate <= this.startDate) {
            this.$message.warning('End time must be greater than start time!');
            this.endDate = '';
          }
        }

        this.pickerOptionsStart = Object.assign({}, this.pickerOptionsStart, {
          disabledDate: (time) => {
            if (this.endDate) {
              return time.getTime() > this.endDate;
            }
          },
        });
      },

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Example code for implementing dynamic skinning with vue+element
  • Integration practice of Vue+Element background management framework
  • Antdesign-vue combined with sortablejs to achieve the function of dragging and sorting two tables
  • Detailed explanation of dragging table columns using Vue Element Sortablejs

<<:  Nginx installation error solution

>>:  Analysis of Linux configuration to achieve key-free login process

Recommend

Summary of basic usage of js array

Preface Arrays are a special kind of object. Ther...

Detailed explanation of the use of CSS3 rgb and rgba (transparent color)

I believe everyone is very sensitive to colors. C...

Nginx prohibits direct access via IP and redirects to a custom 500 page

Directly to the configuration file server { liste...

How to use docker compose to build fastDFS file server

The previous article introduced a detailed exampl...

Detailed explanation of Vuex environment

Table of contents Build Vuex environment Summariz...

Detailed explanation of efficient MySQL paging

Preface Usually, a "paging" strategy is...

Docker-compose steps to configure the spring environment

Recently, I need to package the project for membe...

Nginx routing forwarding and reverse proxy location configuration implementation

Three ways to configure Nginx The first method di...

Common rule priority issues of Nginx location

Table of contents 1. Location / Matching 2. Locat...

Design Reference Beautiful and Original Blog Design

All blogs listed below are original and uniquely ...

About the implementation of JavaScript carousel

Today is another very practical case. Just hearin...

Detailed explanation of Vue.js directive custom instructions

Customize a demo command The syntax of Vue custom...