vue實現(xiàn)打卡功能
本文實例為大家分享了vue實現(xiàn)打卡功能的具體代碼,供大家參考,具體內(nèi)容如下
記錄使用vue實現(xiàn)移動端日歷打卡樣式
template
compareToNow:與當(dāng)前時間比較
-1:小于當(dāng)前時間
0:今天
1:大于當(dāng)前時間
<!-- @click="todo" 實現(xiàn)打卡功能 --> <div v-if="compareToNow(item) === 1" @click="todo">{{ item.date }}</div>
<!-- @click="todo" 實現(xiàn)補卡功能 --> ?<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" style="border-bottom: 1px solid #cccccc"> ? ? ? <div v-for="(item,index) in weeks" :key="index">{{ item }}</div> ? ? </div> ? ? <div class="container" style="padding: 1vh 1vh 3vh 1vh;"> ? ? ? <div v-for="(item,index) in data" :key="index"> ? ? ? ? <div v-if="compareToNow(item) === 0" style="color: #2d8cf0">{{ 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">補卡</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>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue?Electron實現(xiàn)輸入法自動刷字?jǐn)?shù)功能詳解
這篇文章主要介紹了Vue?Electron實現(xiàn)輸入法自動刷字?jǐn)?shù)功能,文中的示例代碼講解詳細(xì),對我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以跟隨小編一起了解一下2022-12-12vue列表數(shù)據(jù)發(fā)生變化指令沒有更新問題及解決方法
這篇文章主要介紹了vue中使用指令,列表數(shù)據(jù)發(fā)生變化指令沒有更新問題,本文給出了解決辦法,需要的朋友可以參考下2020-01-01Vue數(shù)據(jù)監(jiān)聽方法watch的使用
這篇文章主要介紹了Vue數(shù)據(jù)監(jiān)聽方法watch的使用,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-03-03vue-photo-preview圖片預(yù)覽失效的問題及解決
這篇文章主要介紹了vue-photo-preview圖片預(yù)覽失效的問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-09-09vue中的$emit 與$on父子組件與兄弟組件的之間通信方式
本文主要對vue 用$emit 與 $on 來進行組件之間的數(shù)據(jù)傳輸。重點給大家介紹vue中的$emit 與$on父子組件與兄弟組件的之間通信方式,感興趣的朋友一起看看2018-05-05淺談VueJS SSR 后端繪制內(nèi)存泄漏的相關(guān)解決經(jīng)驗
這次我想給大家介紹的內(nèi)存泄漏的定位方法,并非工具的使用。而是一些經(jīng)驗的總結(jié),也就是我所知道的 VueJS SSR 中最容易出現(xiàn)內(nèi)存泄漏的地方,非常具有實用價值,需要的朋友可以參考下2018-12-12element-ui tooltip修改背景顏色和箭頭顏色的實現(xiàn)
這篇文章主要介紹了element-ui tooltip修改背景顏色和箭頭顏色的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12