To realize the page

It is required to obtain the date and time of the day when clicking “Add”, and after the user fills in the information, the submission time is the latest time, which requires the time to be updated in real time. I didn’t write any code during the seven-day National Day holiday, and I felt headache instantly…

The form submission

Use Element UI’s Form form for submission

<el-form-item
                  label="Time:"
                  :label-width="formLabelWidth"
                  prop="time"
                >
                  <el-date-picker
                    v-model="queryParamset.time"
                    type="datetime"
                    placeholder="Select date and time"
                  >
                  </el-date-picker>
                </el-form-item>
Copy the code

Add form validation

 <el-form
          :model="queryParamset"
          :rules="rules"
          ref="queryParamset"
          label-width="100px"
        >
     
Copy the code
   
         // New mandatory
      rules: {
        time: [{required: true.message: "Please select a date".trigger: "change"],},Copy the code

Define fields in the form (directly back-end fields)

// Add parameters
      queryParamset: {
        order: 1.time: undefined.// Date and time
        title: undefined.content: undefined.emotion: undefined.emergency: undefined.risk: undefined.warning_value: undefined.warning: undefined.rs: undefined.area: undefined.field: undefined.zdtfsj: false.gfsj: false.qtxsj: false.warning_sync: false.ds: undefined,},Copy the code

Gets the current date and time

 // Get the current time and date
    getNowTime() {
      var now = new Date(a);var year = now.getFullYear(); / / for years
      var month = now.getMonth();/ / for months
      var date = now.getDate();/ / for days
      var hours = now.getHours();// Get the hour
      var minutes = now.getMinutes();// Get minutes
      var seconds = now.getSeconds();/ / for seconds
      month = month + 1;
      month = month.toString().padStart(2."0");
      date = date.toString().padStart(2."0");
      var defaultDate = `${year}-${month}-${date} ${hours}:${minutes}:${seconds}`;
      this.$set(this.queryParamset, "time", defaultDate);// Assign to the time defined in the form
    },

Copy the code

Real-time time refresh

Define a timestamp in Created, and then call the method to get the time to implement real-time time refresh

created() {
    setInterval(() = > {
      this.getNowTime();
    }, 500);
  
  },
Copy the code

When the form is submitted, the submission time is the latest time when the user completes the form, clicks submit, and finally thanks the big guy for the article