element ui 实现列绑定按照指定时间显示倒计时

table

intervalTime 是我设置的一个名为变量时间的属性

<el-table-column label="剩余逾期时间" align="center" prop="intervalTime">
     <template slot-scope="scope">
       <span style="color: red"> <i class="el-icon-time"></i>{{scope.row.intervalTime}}</span>
     </template>
</el-table-column>

Vue

//获取数据,在获取数据的时候调用绑定列计时
getList() {
      this.loading = true;
      listCirculation(this.queryParams).then(response => {
        this.circulationList = response.rows;
        this.total = response.total;
        this.loading = false;
        if(this.circulationList.length > 0){
          this.circulationList.forEach((el)=>{
            this.countDown(el)
          })
        }
      });
   },
    /** 倒计时*/
    countDown(row) {
    // acceptanceOverTime 是我后台返回的截止时间
      if(row.status == 1){
        let thi = this;
        setInterval((thi) => {
          row.intervalTime =  thi.formatDuring(new Date(row.acceptanceOverTime) - new Date());
        }, 10000); //这边采取的是10秒调用一次
        //这里采用简单写法,直接在查询的时候调用一次,不用等定时器调用
        row.intervalTime = this.formatDuring(new Date(row.acceptanceOverTime) - new Date());
      }
    },
    formatDuring (mss) {
      if(mss > 0){
        let hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)) // 得到小时
        let minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60)) // 得到分钟数
        //获取分钟
        let str1 = minutes < 10 ? ('0' + minutes) : minutes
        
        /*得到秒数
        let seconds = (mss % (1000 * 60)) / 1000
        let str2 = seconds < 10 ? ('0' + seconds) : seconds*/
        return hours + '小时' + str1 + '分钟';
      }else{
        return '已逾期';
      }
    },
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值