The use of filters in vue projects

When the interface data is no longer a simple process, it is not the optimal solution to write all in the template. At this time, you need to use the filters method to process the data. Then use it on the page.

<el-table-column label="失联时间" align="center" prop="lostTime" width="180" sortable>
        <template slot-scope="scope">
          已有<span style="color: red;">{
   
   { scope.row.followTime | lostTime }}</span>天未联系该客户
        </template>
      </el-table-column>


    filters: {
      //将接口获取的时间戳进行处理,并转换成天数应用于页面
      lostTime: function (number) {
        const diff = new Date().getTime() - number
        return Math.floor(diff / (24 * 3600 * 1000));
      }
    },

 

Guess you like

Origin blog.csdn.net/m0_65274248/article/details/128058396