First you need to get the order time from the back end

let orderDate =new Date(res.data.data.created_at)

Calculate millisecond value

let nowTime = new Date().getTime(); let orderDate =new Date(res.data.data.created_at); let times =orderDate - parseInt(nowTime / 1000);

The countdown

changeTime(num) {
  var hours = parseInt(countDownTime/60/60);
  var minutes =parseInt(num/60%60);
  var seconds =parseInt(num%60);
  this.timeTxt = `${hours}时${minutes}分${seconds}秒`;
},
Copy the code

First get the current countdown minutes and seconds, and then start the timer

`if (times <= 0) { this.orderStatus = false; }

this.changeTime(times); this.timer = setInterval(() => { times-=1; this.changeTime(times); if (times <= 0) { clearInterval(this.timer); this.orderStatus = false; }}, 1000);Copy the code