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:
|
>>: A complete list of commonly used Linux commands (recommended collection)
1. I searched for a long time on the Internet but...
1. Linux under VMware Workstation: 1. Update sour...
1. Overview The information_schema database is th...
This article shares the specific code of JavaScri...
Table of contents Preface Actual Combat 1. No loc...
Table of contents Preface How to switch between m...
This article example shares the specific code of ...
This article analyzes the process of shutting dow...
Table property settings that work well: Copy code ...
nginx traffic control Rate-limiting is a very use...
There was no problem connecting to the database y...
I used the dialog in closure and drew a dialog wit...
Preface Mobile devices have higher requirements f...
introduction Let's start with our content. I ...
MySQL 5.7 installation We are learning MySQL data...