本文主要是介绍Vue考试倒计时和计算考试用时,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
先上效果
代码实现
<template><div>倒计时: {{ keepTime }}</div>
</template><script>
export default {data() {return {keepTime: "",};},created() {this.StartCountDown();},methods: {// 开始时间StartCountDown() {var mydate = new Date();mydate.setMinutes(mydate.getMinutes() + 90); //获取后端返回的时间this.settime = mydate;// 时间到执行停止let time = setInterval(() => {if (this.flag == true) {clearInterval(time);}this.timeDown();}, 100);},// 转换timeDown() {const endTime = new Date(this.settime);const nowTime = new Date();let leftTime = parseInt((endTime.getTime() - nowTime.getTime()) / 1000);let d = parseInt(leftTime / (24 * 60 * 60));let h = this.formate(parseInt((leftTime / (60 * 60)) % 24));let m = this.formate(parseInt((leftTime / 60) % 60));let s = this.formate(parseInt(leftTime % 60));if (leftTime <= 0) {}this.keepTime = `${h}:${m}:${s}`;//计算考试时间//var parts = this.keepTime.split(":");// var num = parseInt(parts[0]) * 60 + parseInt(parts[1]) + parseInt(parts[2]) / 60;// var minutes = Math.floor(num * 100) / 100;//var timelength = this.WhenTime - minutes;//this.WhenTime 为考试时间如:100分钟减去所转换的时间// this.timelengthasd = Math.ceil(timelength);//向上取整不到一分钟按一分钟算},formate(time) {if (time >= 10) {return time;} else {return `0${time}`;}},},
};
</script><style>
</style>
这篇关于Vue考试倒计时和计算考试用时的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!