vue實(shí)現(xiàn)點(diǎn)擊按鈕倒計(jì)時
本文實(shí)例為大家分享了vue實(shí)現(xiàn)點(diǎn)擊按鈕倒計(jì)時的具體代碼,供大家參考,具體內(nèi)容如下
實(shí)現(xiàn)效果:
1.點(diǎn)擊開始按鈕啟動計(jì)時

2.點(diǎn)擊重置按鈕計(jì)時恢復(fù)到00:00:00
3.點(diǎn)擊暫停按鈕暫停計(jì)時
Vue代碼:
<template>
? <div>
? ? <div class="timeContainer">{{ time }}</div>
? ? <a-button style="margin-right: 20px" type="primary" @click="start"
? ? ? >開始</a-button
? ? >
? ? <a-button style="margin-right: 20px" type="primary" @click="reset"
? ? ? >重置</a-button
? ? >
? ? <a-button type="primary" @click="end">暫停</a-button>
? </div>
</template>
<script>
export default {
? data() {
? ? return {
? ? ? flag: null,
? ? ? hour: 0,
? ? ? minute: 0,
? ? ? second: 0,
? ? ? time: "00:00:00",
? ? };
? },
? methods: {
? ? //開始計(jì)時
? ? start() {
? ? ? this.flag = setInterval(() => {
? ? ? ? this.second = this.second + 1;
? ? ? ? if (this.second >= 60) {
? ? ? ? ? this.second = 0;
? ? ? ? ? this.minute = this.minute + 1;
? ? ? ? }
? ? ? ? if (this.minute >= 60) {
? ? ? ? ? this.minute = 0;
? ? ? ? ? this.hour = this.hour + 1;
? ? ? ? }
? ? ? ? this.time =
? ? ? ? ? this.complZero(this.hour) +
? ? ? ? ? ":" +
? ? ? ? ? this.complZero(this.minute) +
? ? ? ? ? ":" +
? ? ? ? ? this.complZero(this.second);
? ? ? }, 1000);
? ? },
? ? //重新計(jì)時
? ? reset() {
? ? ? window.clearInterval(this.flag);
? ? ? this.hour = 0;
? ? ? this.minute = 0;
? ? ? this.second = 0;
? ? ? this.time = "00:00:00";
? ? },
? ? //暫停計(jì)時
? ? end() {
? ? ? this.flag = clearInterval(this.flag);
? ? },
? ? //補(bǔ)零
? ? complZero(n) {
? ? ? return n < 10 ? "0" + n : "" + n;
? ? },
? },
};
</script>
<style>
.timeContainer {
? font-size: 40px;
? margin-bottom: 10px;
}
</style>以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue學(xué)習(xí)筆記進(jìn)階篇之多元素及多組件過渡
本篇文章主要介紹了Vue學(xué)習(xí)筆記進(jìn)階篇之多元素及多組件過渡,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-07-07
vue實(shí)現(xiàn)鼠標(biāo)滑動預(yù)覽視頻封面組件示例詳解
這篇文章主要為大家介紹了vue實(shí)現(xiàn)鼠標(biāo)滑動預(yù)覽視頻封面組件示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07
vue-music 使用better-scroll遇到輪播圖不能自動輪播問題
根據(jù)vue-music視頻中slider組建的使用,當(dāng)安裝新版本的better-scroll,輪播組件,不能正常輪播。如何解決這個問題呢,下面小編給大家?guī)砹藇ue-music 使用better-scroll遇到輪播圖不能自動輪播問題,感興趣的朋友一起看看吧2018-12-12

