Detailed explanation of how to use the calendar plugin implemented in Vue.js

Detailed explanation of how to use the calendar plugin implemented in Vue.js

The function to be implemented today is the following function: vue.js simulation calendar plug-in

Okay, no more nonsense, let’s get straight to the code

css:

*{
     margin: 0;
     padding: 0;
     -webkit-box-sizing: border-box;
     -moz-box-sizing: border-box;
     box-sizing: border-box;
        }
        #app{
            width: 1000px;
            margin: 10px auto;
        }
        .calender{
            width: 1000px;
        }
        .calender table{
            width: 1000px;
        }
        .calender table,th,tr,td{
            border:1px solid #333333;
            border-collapse: collapse;
        }
        .calender td{
            height: 100px;
            vertical-align: top;
            text-align: left;
            padding: 5px 0 0 5px;
            font-size: 13px;
        }
        .calender td.cur{
            color:red;
        }

html:

<div id="app">
    <div class="calender">
        <table>
            <caption>
                <select v-model.number="year">
                    <option v-for="i of 490">{{i+1969}}</option>
                </select>
                <select v-model.number="month">
                    <option v-for="i of 12">{{i}}</option>
                </select>
            </caption>
            <thead>
            <tr>
                <th>Sunday</th>
                <th>Monday</th>
                <th>Tuesday</th>
                <th>Wednesday</th>
                <th>Thursday</th>
                <th>Friday</th>
                <th>Saturday</th>
            </tr>
            </thead>
            <tbody>
            <!--index starts from 0 and i starts from 1-->
            <tr v-for="(a,index) of calender.length / 7" >
                <td v-for="i of 7" :class="{cur:calender[index * 7 + (i - 1)].cur }">{{calender[index * 7 + (i - 1)].fullDay}}</td>
            </tr>
            </tbody>
        </table>
    </div>
</div>

js:

var vm = new Vue({
        el:'#app',
        data:{
            year:2018,
            month:1
        },
        computed:{
            calender(){
                var arr = [];

                //new data has three parameters: 1. year 2. month 3. The default is 1. If it is 0, it means the last day of the previous month - the first two days 3 the day after tomorrow var nowMonthLength = new Date(this.year,this.month,0).getDate();
                var nowMonthFirstWeek = new Date(this.year,this.month-1).getDay();
                var lastMonthLength = new Date(this.year,this.month-1,0).getDate();
                console.log('This month has:' + nowMonthLength);
                console.log('First day of this month' + nowMonthFirstWeek);
                console.log('last month length' + lastMonthLength);

                // this.month = parseInt(this.month);
                //Which month is the previous month of each month? var pmonth = this.month == 1 ? 12 : this.month - 1;
                //Previous year var pyear = this.month == 1 ? this.year - 1 :this.year;
                //Next month var nmonth = this.month == 12 ? 1 : this.month + 1;
                //Next month var nyear = this.month == 12 ? this.year + 1 : this.year;
                //Zero-filling function // function toTwo(n) {
                // return n < 10 ? '0' + n : n;
                // }
                function build(n) {
                    return n.toString().length > 1 ? n.toString() : '0' + n.toString();
                }
                // Add the last few days of last month while(nowMonthFirstWeek--){
                    arr.unshift({
                        day:lastMonthLength,
                        cur:true,
                        fullDay:`${pyear}-${buling(pmonth)}-${buling(lastMonthLength)}`
                    });
                    lastMonthLength--
                }
                console.log(arr);

                //Days of this month var _a = 1;
                while(nowMonthLength--){
                    arr.push({
                        day:_a,
                        cur:false,
                        fullDay:`${this.year}-${buling(this.month)}-${buling(_a)}`
                    });
                    _a++
                }

                //Complete next month var nextLength = arr.length > 35 ? 42 - arr.length : 35 - arr.length;
                _a = 1;
                while (nextLength--){
                    arr.push({
                        day:_a,
                        cur:true,
                        fullDay:`${nyear}-${buling(nmonth)}-${buling(_a)}`
                    });
                    _a++
                }
                return arr;
            }
        }
    })

Note: You need to import your local vue.js file first before it can run properly!!!

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • How to use the vue-video-player plugin for vue video playback
  • A simple way to use the Lodop plugin in Vue to implement printing function
  • How to use the Vue paging plugin
  • Detailed explanation of how to use the Vue WeChat sharing plug-in
  • How to use vue-layer bullet box plug-in in vue project
  • Example of using jsonp plugin in vue
  • Detailed explanation of how to use vue-cropper, a Vue image cropping plugin
  • Detailed sharing of Vue plugin usage

<<:  mysql 8.0.20 winx64.zip compressed version installation and configuration method graphic tutorial

>>:  A complete list of commonly used Linux commands (recommended collection)

Recommend

Introduction to Linux compression and decompression commands

Table of contents Common compression formats: gz ...

Vue template compilation details

Table of contents 1. parse 1.1 Rules for intercep...

PyTorch development environment installation tutorial under Windows

Anaconda Installation Anaconda is a software pack...

Element-ui directly clicks on the cell in the table to edit

Table of contents Achieve results Implementation ...

How to mount a disk in Linux

When using a virtual machine, you may find that t...

Detailed explanation of component development of Vue drop-down menu

This article example shares the specific code for...

HTML table markup tutorial (14): table header

<br />In HTML language, you can automaticall...

Chinese and English font name comparison table (including Founder and Arphic)

In CSS files, we often see some font names become...

How to use resident nodes for layer management in CocosCreator

CocosCreator version: 2.3.4 Most games have layer...

MySQL 5.7.33 installation process detailed illustration

Table of contents Installation package download I...

MySQL 5.7 Common Data Types

——Notes from "MySQL in Simple Terms (Second ...

HTML table tag tutorial (17): table title vertical alignment attribute VALIGN

The table caption can be placed above or below th...