momentjs在vue中的用法
Posted 进击的single
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了momentjs在vue中的用法相关的知识,希望对你有一定的参考价值。
js代码
import moment from ‘moment‘;
const jsCountDown = document.getElementById(‘js-countdown‘);
const targetTime = new Date(‘2018-10-4‘);
const countdownFn = () =>{
const now = moment();
const end = moment(targetTime);
const diffDay = now.diff(end,‘days‘);
const diffH = now.diff(end,‘hours‘) % 24;
const diffM = now.diff(end,‘minutes‘) % 60;
const diff = now.diff(end, ‘seconds‘) % 60;
// console.log(diffDay,diffH,diffM);
// console.log(diffDay);
jsCountDown.querySelector(‘.day‘).innerhtml = - diffDay;
jsCountDown.querySelector(‘.hours‘).innerHTML = - diffH;
jsCountDown.querySelector(‘.minutes‘).innerHTML = - diffM;
jsCountDown.querySelector(‘.second‘).innerHTML = - diff;
// if (diff >= 0) {
// return;
// }
setTimeout(() => {
countdownFn();
}, 10);
}
countdownFn();
html代码
<div class="inner" id="js-countdown">
<i class="icon-time"></i>
<span class="day">1</span>
天
<span class="hours">1</span>
时
<span class="minutes">1</span>
分
<span class="second">1</span>
秒
</div>
以上是关于momentjs在vue中的用法的主要内容,如果未能解决你的问题,请参考以下文章
Polymer WebComponent中的Momentjs - 全局未定义