[vue] Time formatting and forwarding decimals to percentages

1. Time formatting

(1) Input parameters passed from the front end to the background

Time selector, the input format is: ["2022-02-27T16:00:00.000Z", "2022-02-27T16:00:00.000Z"] The
format required by the background is: ["2022-02-27" , "2022-02-27"]
code implementation:

 <el-form-item label="创建日期">
            <el-date-picker
              v-model="reports.query.create_date"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期">
            </el-date-picker>
            </el-form-item>

(2) The background returns data to the front end for display

The format returned by the background is: ["2022-02-27T16:00:00.000Z", "2022-02-27T16:00:00.000Z"]
The format that the front end wants to display is:
insert image description here
code implementation:

  <el-table-column
      align="center"
      prop="create_date"
      label="创建日期"
      sortable
      :formatter="dateFormat"
      width="180">
    </el-table-column>
 methods: {
    
    
 	dateFormat: function(row, column) {
    
    
      var t = new Date(row.create_date)
      return t.getFullYear() + '-' + t.getMonth() + 1 + '-' + t.getDate() + ' ' + t.getHours() + ':' + t.getMinutes() + ':' + t.getSeconds()
    }
 }

2. Convert decimals into percentages, keep three or two decimal places

Code:

    <el-table-column
      align="center"
      prop="passing_rate"
      label="通过率"
      sortable
      :formatter="ChangeToPercentage"
      width="100">
    </el-table-column>
 methods: {
    
    
 	ChangeToPercentage: function(row, column) {
    
    
      var percent = (row[column.property] * 100).toFixed(2) + '%'
      return percent
    }
 }

Guess you like

Origin blog.csdn.net/daxiangaifashi/article/details/123306518