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

MySQL 5.7.21 installation and configuration tutorial

The simple installation configuration of mysql5.7...

Vue uses three methods to refresh the page

When we are writing projects, we often encounter ...

SQL implementation of LeetCode (181. Employees earn more than managers)

[LeetCode] 181.Employees Earning More Than Their ...

Mysql method to copy a column of data in one table to a column in another table

mysql copy one table column to another table Some...

Summary of commonly used tool functions in Vue projects

Table of contents Preface 1. Custom focus command...

JavaScript history object explained

Table of contents 1. Route navigation 2. History ...

Nginx content cache and common parameter configuration details

Use scenarios: The project's pages need to lo...

js drag and drop table to realize content calculation

This article example shares the specific code of ...

How to implement function currying and decurrying in Javascript

Function currying (black question mark face)? ? ?...

Two problems encountered when deploying rabbitmq with Docker

1. Background The following two problems are enco...

Do not start CSS pseudo-class names with numbers

When newbies develop div+css, they need to name t...

Vue implements the magnifying glass function of the product details page

This article shares the specific code of Vue to i...

Deep understanding of JavaScript syntax and code structure

Table of contents Overview Functionality and read...

How to install MySQL under Linux (yum and source code compilation)

Here are two ways to install MySQL under Linux: y...