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)
Table of contents Common compression formats: gz ...
Table of contents 1. parse 1.1 Rules for intercep...
Table of contents 1. Introduction 2. About vue-si...
Anaconda Installation Anaconda is a software pack...
Table of contents Achieve results Implementation ...
Timer Effects: <div> <font id='timeC...
When using a virtual machine, you may find that t...
This article example shares the specific code for...
<br />In HTML language, you can automaticall...
This article records the installation and configu...
In CSS files, we often see some font names become...
CocosCreator version: 2.3.4 Most games have layer...
Table of contents Installation package download I...
——Notes from "MySQL in Simple Terms (Second ...
The table caption can be placed above or below th...