您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“vue怎么實(shí)現(xiàn)打卡功能”,感興趣的朋友不妨來看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“vue怎么實(shí)現(xiàn)打卡功能”吧!
記錄使用vue實(shí)現(xiàn)移動(dòng)端日歷打卡樣式
template
compareToNow:與當(dāng)前時(shí)間比較
-1:小于當(dāng)前時(shí)間
0:今天
1:大于當(dāng)前時(shí)間
<!-- @click="todo" 實(shí)現(xiàn)打卡功能 --> <div v-if="compareToNow(item) === 1" @click="todo">{{ item.date }}</div>
<!-- @click="todo" 實(shí)現(xiàn)補(bǔ)卡功能 --> <div v-if="compareToNow(item) === -1" @click="todo" class="otherDay">
<template> <div> <div class="top-title"> <div><span @click="lastMonth" class="link">?</span></div> <div><span>{{year}}年{{month}}月</span></div> <div><span @click="nextMonth" class="link">?</span></div> </div> <div class="container" > <div v-for="(item,index) in weeks" :key="index">{{ item }}</div> </div> <div class="container" > <div v-for="(item,index) in data" :key="index"> <div v-if="compareToNow(item) === 0" >{{ item.date }}</div> <div v-if="compareToNow(item) === 1">{{ item.date }}</div> <div v-if="compareToNow(item) === -1" class="otherDay"> <div>{{ item.date }}</div> <div class="date-desc">補(bǔ)卡</div> </div> </div> </div> </div> </template>
script
<script> export default { data() { return { today:new Date(), now:new Date(), weeks:["日","一","二","三","四","五","六"], year:"", month:"", date:"", firstDay:"", data:[], }; }, mounted() { this.getNow(); }, methods:{ getNow(){ this.year = this.now.getFullYear(); this.month = this.now.getMonth() + 1; this.date = this.now.getDate(); this.now.setDate(1); this.firstDay = this.now.getDay(); this.initData(); }, getMonthDay(month){ if ([1,3,5,7,8,10,12].includes(month)) { return 31 } else if ([4,6,9,11].includes(month)) { return 30 } else if (month === 2) { // 判斷當(dāng)年是否為閏年 if ( (this.year % 4 === 0 && this.year % 100 !== 0) || this.year % 400 === 0 ) { return 29 } else { return 28 } } }, initData(){ this.data = []; let days = this.getMonthDay(this.month); for (let i = 0; i < this.firstDay; i++) { this.data.push({ year:"", month:"", date:"", }); } for (let i = 0; i < days; i++) { this.data.push( { year: this.year, month: this.month, date: i + 1, } ); } }, lastMonth(){ this.now.setMonth(this.now.getMonth() - 1); this.getNow(); }, nextMonth(){ this.now.setMonth(this.now.getMonth() + 1); this.getNow(); }, compareToNow(item){ if (item.year && item.month && item.date) { let date1 = new Date(); date1.setFullYear(item.year) date1.setMonth(item.month - 1) date1.setDate(item.date) date1.setHours(0) date1.setMinutes(0) date1.setSeconds(0) let now = new Date(); now.setHours(0) now.setMinutes(0) now.setSeconds(0) if (date1.getTime() > now.getTime()){ return 1 }else if (date1.getTime() === now.getTime()){ return 0 }else if (date1.getTime() < now.getTime()){ return -1 } } } } } </script>
style
/* 背景圖片 background:url 和 background-size 可注釋 */ <style scoped lang="less"> .top-title{ display: grid; grid-template-columns:repeat(3,1fr); grid-auto-rows:40px; grid-gap:1rem; background-color: #FFFFFF; border-bottom: 1px solid #cccccc; line-height: 40px; } .container{ display: grid; grid-template-columns:repeat(7,1fr); grid-auto-rows:40px; grid-gap:1rem; background-color: #FFFFFF; line-height: 40px; div{ text-align: center; } } .today{ background: url("../assets/circle_success.png") no-repeat center center; background-size: 95% 95%; position: relative; } .otherDay{ background: url("../assets/circle_error.png") no-repeat center center; background-size: 95% 95%; position: relative; } .link{ font-size: 14px; color: #2d8cf0; } .date-desc{ display: block; position: absolute; top: 6.8vw; left: 1.5vw; font-size: 2.3vw; color: green; } </style>
到此,相信大家對(duì)“vue怎么實(shí)現(xiàn)打卡功能”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。