最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue實現(xiàn)日歷組件

 更新時間:2022年04月18日 09:46:55   作者:zxb89757  
這篇文章主要為大家詳細介紹了vue實現(xiàn)日歷組件,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

基于VUE實現(xiàn)日歷組件,供大家參考,具體內(nèi)容如下

年和月份是使用輸入框來切換的,沒有做成選擇框,??和??切換月份,紅色選取是選取的日期
實現(xiàn)思路和網(wǎng)上的大多數(shù)一樣,首先是把月份的天數(shù)存進一個數(shù)組,

monthDay:[31,'',31,30,31,30,31,31,30,31,30,31],

由于二月的天數(shù)是不確定的,所以就先設置為空

然后去求選擇的月份的第一天是星期幾,通過 Date.getDay()函數(shù),這個函數(shù)有一個注意事項,就是如果是星期天,他會返回0,這需要我們自己去處理一下

圖中,2019年1月1號是星期二,所以前面就要給它一個空格塊
下面代碼中第一層循環(huán)就是在循環(huán)空格塊,spaceDay表示需要幾個空格

<p v-for="item in spaceDay" :key="item.id"></p>
<p v-for="(item,idx) in (monthDay[this.month-1] || 30)" @click="setDay(idx)" :class="idx==activeDay?'active':''" :key="item.id">{{item}}</p>

下面貼出完整代碼

<template>
? ? <div id="calender">
? ? ? ? <div class="txt-c p-10">
? ? ? ? ? ? <span @click="prev"> ?? </span>
? ? ? ? ? ? <input type="text" v-model="year">年
? ? ? ? ? ? <input type="text" v-model="month" class="month">月
? ? ? ? ? ? <span @click="next"> ????? </span>
? ? ? ? </div>
? ? ? ? <div class="weekDay flex jc-sb p-5 day" >
? ? ? ? ? ? <p v-for="item in weekList" :key="item.id">{{item}}</p>
? ? ? ? </div>
? ? ? ? <div class="weekDay flex p-5 day">
? ? ? ? ? ? <p v-for="item in spaceDay" :key="item.id"></p>
? ? ? ? ? ? <p v-for="(item,idx) in (monthDay[this.month-1] || 30)" @click="setDay(idx)" :class="idx==activeDay?'active':''" :key="item.id">{{item}}</p>
? ? ? ? </div>
? ? </div>
</template>

<script>
? ? export default {
? ? ? ? name: "calender",
? ? ? ? data(){
? ? ? ? ? ? return{
? ? ? ? ? ? ? ? year: '', // 年份
? ? ? ? ? ? ? ? month: '', // 月份
? ? ? ? ? ? ? ? day: '', // 天數(shù)
? ? ? ? ? ? ? ? current: '', // 當前時間
? ? ? ? ? ? ? ? weekList:['周一','周二','周三','周四','周五','周六','周日'],
? ? ? ? ? ? ? ? monthDay:[31,'',31,30,31,30,31,31,30,31,30,31],
? ? ? ? ? ? ? ? activeDay: '', // 選中的日期
? ? ? ? ? ? ? ? spaceDay: '', // 每個月第一天是星期幾
? ? ? ? ? ? ? ? February:'' // 判斷2月份的天數(shù)
? ? ? ? ? ? }
? ? ? ? },
? ? ? ? created(){
? ? ? ? ? ? this.current = new Date()
? ? ? ? ? ? this.getTheCurrentDate()
? ? ? ? ? ? this.getMonthFisrtDay()
? ? ? ? ? ? this.February = this.isLeapYear(this.year) ? 28 : 29
? ? ? ? ? ? this.monthDay.splice(1,1,this.February)
? ? ? ? },
? ? ? ? watch:{
? ? ? ? ? month(){
? ? ? ? ? ? ? if(this.month>12||this.month<1){
? ? ? ? ? ? ? ? ? console.log('請輸入正確月份')
? ? ? ? ? ? ? ? ? return
? ? ? ? ? ? ? }
? ? ? ? ? ? ? this.getMonthFisrtDay()
? ? ? ? ? },
? ? ? ? ? year(){
? ? ? ? ? ? ? this.getMonthFisrtDay()
? ? ? ? ? }
? ? ? ? },
? ? ? ? methods:{
? ? ? ? ? ? // 判斷是否是閏年
? ? ? ? ? ? isLeapYear(year){
? ? ? ? ? ??
? ? ? ? ? ? ? ? return year % 4 == 0 && year % 100 != 0 ||year % 400 == 0;
? ? ? ? ? ? },
? ? ? ? ? ? // 選取特定天數(shù)
? ? ? ? ? ? setDay(idx){
? ? ? ? ? ? ? ? this.activeDay = idx
? ? ? ? ? ? ? ? this.day = idx + 1
? ? ? ? ? ? ? ? console.log('選擇的日期是'+this.year+' '+this.month+' '+this.day)
? ? ? ? ? ? },
? ? ? ? ? ? // 判斷月份的第一天是星期幾
? ? ? ? ? ? getMonthFisrtDay(){
? ? ? ? ? ? ? ? var firstDayOfCurrentMonth = new Date(this.year,this.month-1,1) // 某年某月的第一天
? ? ? ? ? ? ? ? if(firstDayOfCurrentMonth.getDay() == 0){
? ? ? ? ? ? ? ? ? ? this.spaceDay = 6
? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? this.spaceDay = firstDayOfCurrentMonth.getDay() - 1
? ? ? ? ? ? ? ? }
? ? ? ? ? ? },
? ? ? ? ? ? // 獲取當前的日期
? ? ? ? ? ? getTheCurrentDate(){
? ? ? ? ? ? ? ? this.year = this.current.getFullYear()
? ? ? ? ? ? ? ? this.month = this.current.getMonth() + 1
? ? ? ? ? ? ? ? this.day = this.current.getDate()
? ? ? ? ? ? },
? ? ? ? ? ? prev(){
? ? ? ? ? ? ? ? if(this.month==1){
? ? ? ? ? ? ? ? ? ? this.year--
? ? ? ? ? ? ? ? ? ? this.month=12
? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? this.month--
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? this.activeDay = 0
? ? ? ? ? ? ? ? this.getMonthFisrtDay()
? ? ? ? ? ? },
? ? ? ? ? ? next(){
? ? ? ? ? ? ? ? if(this.month==12){
? ? ? ? ? ? ? ? ? ? this.year++
? ? ? ? ? ? ? ? ? ? this.month=1
? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? this.month++
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? this.activeDay = 0
? ? ? ? ? ? ? ? this.getMonthFisrtDay()
? ? ? ? ? ? }
? ? ? ? }
? ? }
</script>

<style lang="scss" scoped>
#calender{
? ? .txt-c{
? ? ? ? text-align: center;
? ? }
? ? .p-10{
? ? ? ? padding: 2rem;
? ? }
? ? .p-5{
? ? ? ? padding: 1rem;
? ? }
? ? .flex {
? ? ? ? display: flex;
? ? }
? ? .jc-sb{
? ? ? ? justify-content: space-between;
? ? }
? ? input{
? ? ? ? width: 50px;
? ? ? ? &.month{
? ? ? ? ? ? width: 30px;
? ? ? ? }
? ? }
? ? .day{
? ? ? ? flex-wrap: wrap;
? ? ? ? p{
? ? ? ? ? ? width: 14.28%;
? ? ? ? ? ? /*flex: 0 0 0 ;*/
? ? ? ? ? ? text-align: center;
? ? ? ? ? ? line-height: 2.4rem;
? ? ? ? ? ? height: 2.4rem;
? ? ? ? ? ? position: relative;
? ? ? ? ? ? z-index: 100;
? ? ? ? ? ? &.active{
? ? ? ? ? ? ? ? color: #fff;
? ? ? ? ? ? }
? ? ? ? ? ? &.active:before{
? ? ? ? ? ? ? ? content: '';
? ? ? ? ? ? ? ? height: 2.5rem;
? ? ? ? ? ? ? ? width: 2.5rem;
? ? ? ? ? ? ? ? position: absolute;
? ? ? ? ? ? ? ? z-index: -1;
? ? ? ? ? ? ? ? left: 0;
? ? ? ? ? ? ? ? top: 0;
? ? ? ? ? ? ? ? transform: translateX(50%);
? ? ? ? ? ? ? ? border-radius: 50%;
? ? ? ? ? ? ? ? background: #e97163;
? ? ? ? ? ? ? ? color: #fff;
? ? ? ? ? ? }
? ? ? ? }
? ? }
}
</style>

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • 詳解Vue如何手寫一個虛擬列表

    詳解Vue如何手寫一個虛擬列表

    虛擬列表是一種優(yōu)化長列表渲染的技術,它可以在保持流暢性的同時,渲染大量的數(shù)據(jù),本文主要介紹了如何使用vue手寫一個虛擬列表,感興趣的可以了解下
    2024-04-04
  • Vue.js:使用Vue-Router 2實現(xiàn)路由功能介紹

    Vue.js:使用Vue-Router 2實現(xiàn)路由功能介紹

    本篇文章主要介紹了Vue.js:使用Vue-Router 2實現(xiàn)路由功能介紹,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-02-02
  • vue flex 布局實現(xiàn)div均分自動換行的示例代碼

    vue flex 布局實現(xiàn)div均分自動換行的示例代碼

    這篇文章主要介紹了vue flex 布局實現(xiàn)div均分自動換行,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-08-08
  • vue中使用iconfont圖標的過程

    vue中使用iconfont圖標的過程

    這篇文章主要介紹了vue中使用iconfont圖標的過程,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • Vue SSR 組件加載問題

    Vue SSR 組件加載問題

    這篇文章主要介紹了Vue SSR 組件加載問題,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2018-05-05
  • Vue2中如何使用全局事件總線實現(xiàn)任意組件間通信

    Vue2中如何使用全局事件總線實現(xiàn)任意組件間通信

    全局事件總線就是一種組件間通信的方式,適用于任意組件間通信,下面這篇文章主要給大家介紹了關于Vue2中如何使用全局事件總線實現(xiàn)任意組件間通信的相關資料,需要的朋友可以參考下
    2022-12-12
  • 在vue中通過render函數(shù)給子組件設置ref操作

    在vue中通過render函數(shù)給子組件設置ref操作

    這篇文章主要介紹了在vue中通過render函數(shù)給子組件設置ref操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • Vue實現(xiàn)搜索結果高亮顯示關鍵字

    Vue實現(xiàn)搜索結果高亮顯示關鍵字

    這篇文章主要為大家詳細介紹了Vue實現(xiàn)搜索結果高亮顯示關鍵字,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-05-05
  • vue圓形進度條環(huán)形進度條組件內(nèi)部顯示圖片示例

    vue圓形進度條環(huán)形進度條組件內(nèi)部顯示圖片示例

    這篇文章主要為大家介紹了vue圓形進度條環(huán)形進度條組件內(nèi)部顯示圖片示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-11-11
  • Vue 兩個字段聯(lián)合校驗之修改密碼功能的實現(xiàn)

    Vue 兩個字段聯(lián)合校驗之修改密碼功能的實現(xiàn)

    本文以校驗兩次密碼的一致性應用,給出兩個可變屬性值的字段之間的聯(lián)合校驗的典型解決方案,通過實例代碼給大家介紹Vue 兩個字段聯(lián)合校驗之修改密碼功能的實現(xiàn),需要的朋友一起看看吧
    2021-07-07

最新評論

永靖县| 始兴县| 阳山县| 浪卡子县| 兴和县| 泗洪县| 宣城市| 中牟县| 梧州市| 大悟县| 宜章县| 柯坪县| 泸定县| 平顶山市| 宝鸡市| 利川市| 济南市| 榆树市| 牙克石市| 陆丰市| 射洪县| 沁阳市| 大港区| 延长县| 阳信县| 固镇县| 余姚市| 大理市| 政和县| 芷江| 安阳县| 蒙阴县| 华阴市| 吉水县| 徐水县| 江北区| 新晃| 高青县| 亚东县| 万载县| 永兴县|