vue中filters 传入两个参数 / 使用两个filters

.vue

传入两个参数
 {{第一个参数|formatVisitTime(第二个参数)}}

使用两个filters
{{item.CreateTime|formatVisitDate}}

 

format.js

export const formatVisitTime = (beginTime, finishTime) => {
    if (!beginTime) {
        return "--";
    }
    if (!finishTime) {
        return formatDateTime(beginTime, 'hh:mm:ss')
    }
    beginTime = new Date(beginTime);
    finishTime = new Date(finishTime);
    let mss = Math.abs(beginTime.getTime() - finishTime.getTime());
    let hours = Math.floor(mss / (1000 * 60 * 60));
    let minutes = Math.floor((mss % (1000 * 60 * 60)) / (1000 * 60));
    return hours + "小时" + minutes + "分钟";
}

.ts

import format from "@/plugins/format";

@Component({
  filters: {
    formatVisitTime(beginTime, finishTime) {
      return format.formatVisitTime(beginTime, finishTime);
    }
  }
})

 

 

你可能感兴趣的:(vue中filters 传入两个参数 / 使用两个filters)