*初级小白*~ 2023-04-13 11:37 采纳率: 97.9%
浏览 36

关于#vue.js#的问题:表格中的倒计时,如何结束时间endTime减去现在时间(语言-javascript)

表格中的倒计时,如何结束时间endTime减去现在时间,得出还剩几天几时几分钟几秒,超过就得出超时几天几时几分钟几秒


 
<template>
  <a-table :columns="columns" :data-source="dataSource">
    <template #bodyCell="{ column, text }">
      <template v-if="column.dataIndex === 'name'">
        <a>{{ text }}</a>
      </template>
      <template v-if="column.dataIndex === 'time'">
        <a>{{ text }}</a>
      </template>
    </template>
  </a-table>
</template>
<script>
import { defineComponent } from 'vue';
const dataSource = [
  {
    key: '1',
    name: '胡彦斌',
    age: 32,
    address: '西湖区湖底公园1号',
    time:'2023-4-1 00:00:00'
  },
  {
    key: '2',
    name: '胡彦祖',
    age: 42,
    address: '西湖区湖底公园1号',
    time:'2023-5-1 00:00:00'
  },
]
 
const columns = [
  {
    title: '姓名',
    dataIndex: 'name',
    key: 'name',
  },
  {
    title: '年龄',
    dataIndex: 'age',
    key: 'age',
  },
  {
    title: '住址',
    dataIndex: 'address',
    key: 'address',
  },
  {
    title:'倒计时',
    dataIndex:'time',
    key:'time'
  }
]
export default defineComponent({
  setup() {
  
    return {
      dataSource,
      columns,
    };
  },
});
</script>
  • 写回答

1条回答 默认 最新

  • CSDN专家-showbo 2023-04-13 12:40
    关注

    看之前的这个问题,改下getCountdownStr为下面即可

        const getCountdownStr = (time) => {
            time = new Date(time.replace(/-/g, '/'));
            let sec = Math.ceil((time.getTime() - currentTime.value.cur) / 1000);
            let prefix = sec >= 0 ? '还剩' :'超时'
            sec = Math.abs(sec);
            //if (sec <= 0) return '0天0时0分钟0秒';
    
            let day = Math.floor(sec / 24 / 3600);
            sec -= day * 24 * 3600;
            let hour = Math.floor(sec / 3600);
            sec -= hour * 3600;
            let minute = Math.floor(sec / 60);
            sec -= minute * 60;
            return `${prefix}${day}${hour}${minute}${sec}秒`
        }
    
    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 4月13日

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP