vue實(shí)現(xiàn)指定日期之間的倒計(jì)時(shí)
本文實(shí)例為大家分享了vue實(shí)現(xiàn)指定日期之間倒計(jì)時(shí)的具體代碼,供大家參考,具體內(nèi)容如下
效果圖如下
此處使用moment.js日期處理類庫 使用方法如下
npm install moment 或者 yarn add moment
html
<div class="time-down"> <div class="back">{{dayNum}}</div> <div class="font-14 date">天</div> <div class="back">{{hourNum}}</div> <div class="font-14 date">時(shí)</div> <div class="back">{{minuteNum}}</div> <div class="font-14 date">分</div> <div class="back">{{secondNum}}</div> <div class="font-14 date">秒</div> </div>
js
import moment from 'moment'; export default { name: 'TimeRangPage', props: { startTime: String, endTime: String }, data () { return { days: 0, hours: 0, minutes: 0, seconds: 0, timeSetInterval: null, showTimeDown: false, showOver: false }; }, created () { if (moment(new Date()).isBefore(this.startTime)) { this.showTimeDown = true; this.timeDown(); } if (moment(new Date()).isAfter(this.endTime)) this.showOver = true; }, methods: { timeDown () { this.timeSetInterval = setInterval(() => { if (moment(this.startTime).isBefore(moment())) { this.showTimeDown = false; clearInterval(this.timeSetInterval); location.reload(); } let dur = moment.duration(moment(this.startTime) - moment(), 'ms'); this.days = dur.get('days'); this.hours = dur.get('hours'); this.minutes = dur.get('minutes'); this.seconds = dur.get('seconds'); }, 1000); } }, computed: { dayNum () { if (this.days < 10) return '0' + this.days; return this.days; }, hourNum () { if (this.hours < 10) return '0' + this.hours; return this.hours; }, minuteNum () { if (this.minutes < 10) return '0' + this.minutes; return this.minutes; }, secondNum () { if (this.seconds < 10) return '0' + this.seconds; return this.seconds; } } };
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Vue寫一個(gè)簡(jiǎn)單的倒計(jì)時(shí)按鈕功能
- 簡(jiǎn)單實(shí)現(xiàn)vue驗(yàn)證碼60秒倒計(jì)時(shí)功能
- vue2.0實(shí)現(xiàn)倒計(jì)時(shí)的插件(時(shí)間戳 刷新 跳轉(zhuǎn) 都不影響)
- 基于vue的短信驗(yàn)證碼倒計(jì)時(shí)demo
- vue實(shí)現(xiàn)驗(yàn)證碼按鈕倒計(jì)時(shí)功能
- vue中多個(gè)倒計(jì)時(shí)實(shí)現(xiàn)代碼實(shí)例
- vue實(shí)現(xiàn)商城秒殺倒計(jì)時(shí)功能
- vue實(shí)現(xiàn)倒計(jì)時(shí)獲取驗(yàn)證碼效果
- vue設(shè)計(jì)一個(gè)倒計(jì)時(shí)秒殺的組件詳解
- vue+canvas實(shí)現(xiàn)炫酷時(shí)鐘效果的倒計(jì)時(shí)插件(已發(fā)布到npm的vue2插件,開箱即用)
相關(guān)文章
Vue中filter使用及根據(jù)id刪除數(shù)組元素方式
這篇文章主要介紹了Vue中filter使用及根據(jù)id刪除數(shù)組元素方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03axios簡(jiǎn)單實(shí)現(xiàn)小程序延時(shí)loading指示
這篇文章主要介紹了axios簡(jiǎn)單實(shí)現(xiàn)小程序延時(shí)loading指示,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-07-07基于axios請(qǐng)求封裝的vue應(yīng)用實(shí)例代碼
這篇文章主要給大家介紹了基于axios請(qǐng)求封裝的vue應(yīng)用的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05解決vue數(shù)據(jù)不實(shí)時(shí)更新的問題(數(shù)據(jù)更改了,但數(shù)據(jù)不實(shí)時(shí)更新)
這篇文章主要介紹了解決vue數(shù)據(jù)不實(shí)時(shí)更新的問題(數(shù)據(jù)更改了,但數(shù)據(jù)不實(shí)時(shí)更新),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-10-10vue使用高德地圖點(diǎn)擊下鉆上浮效果的實(shí)現(xiàn)思路
這篇文章主要介紹了vue使用高德地圖點(diǎn)擊下鉆 上浮效果的實(shí)現(xiàn)思路,本文以浙江省為例通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2019-10-10Vue實(shí)現(xiàn)模糊查詢的簡(jiǎn)單方法實(shí)例
這篇文章主要給大家介紹了關(guān)于Vue實(shí)現(xiàn)模糊查詢的簡(jiǎn)單方法,在vue中,前端模糊搜索主要是用computed屬性實(shí)現(xiàn),本文通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2021-08-08