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

How to check if a table exists in MySQL and then delete it in batches

1. I searched for a long time on the Internet but...

Detailed explanation of Linux copy and paste in VMware virtual machine

1. Linux under VMware Workstation: 1. Update sour...

Detailed explanation of MySQL information_schema database

1. Overview The information_schema database is th...

Implementing a shopping cart with native JavaScript

This article shares the specific code of JavaScri...

MySQL pessimistic locking and optimistic locking implementation

Table of contents Preface Actual Combat 1. No loc...

Detailed explanation of Vue element plus multi-language switching

Table of contents Preface How to switch between m...

How to implement Vue timer

This article example shares the specific code of ...

How to safely shut down a MySQL instance

This article analyzes the process of shutting dow...

Table related arrangement and Javascript operation table, tr, td

Table property settings that work well: Copy code ...

Implementation of nginx flow control and access control

nginx traffic control Rate-limiting is a very use...

The button has a gray border that is ugly. How to remove it?

I used the dialog in closure and drew a dialog wit...

How to choose transaction isolation level in MySQL project

introduction Let's start with our content. I ...

MySQL5.7.27-winx64 version win10 download and installation tutorial diagram

MySQL 5.7 installation We are learning MySQL data...