国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 熱點 > 微信 > 正文

微信小程序日歷組件使用方法詳解

2024-07-22 01:19:17
字體:
來源:轉載
供稿:網友

這個日歷采用小程序組件化開發,有興趣的同學可以引用本組件(怎么引用不多贅述,自行去微信小程序開發api了解)

wxml

<!--pages/components/calender.wxml--><view class='calender'><view class='operate'><text catchtap='reduce'>減少</text><text catchtap="add">增加</text></view><view class='year'><text>{{year}}年</text><text>{{currentMonth}}月</text></view><view class='week'><block wx:for="{{weekArr}}" wx:key="{{index}}"><text>{{item}}</text></block></view><view class='date'><block wx:for="{{dateArr}}" wx:key="{{index}}"><text>{{item-(weekNum-1)<=0?"":item-(weekNum-1)>yearMonth[currentMonth-1]?"":item-(weekNum-1)}}</text></block></view></view>

js

// pages/components/calender.jsComponent({data:{weekArr:["日","一","二","三","四","五","六"],yearMonth:[],rowNum:"",dateArr:[],currentMonth:"",year:"",weekNum:""},created:function(){},attached:function(){let T = new Date()this.setData({currentMonth: T.getMonth() + 1,year: T.getFullYear()})//判斷閏年let yeartype = (this.data.year % 4 == 0) && (this.data.year % 100 != 0 || this.data.year % 400 == 0)if ( yeartype ){this.setData({yearMonth: [31, 29 , 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]})}else{this.setData({yearMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]})}let currentMonthDay = this.data.year + "-" + this.data.currentMonth +"-01"let weekStr = ""this.setData({weekNum: new Date(currentMonthDay).getDay(),rowNum: Math.ceil((this.data.yearMonth[this.data.currentMonth] + new Date(currentMonthDay).getDay())/7)})for( let i=0 ; i<this.data.rowNum ; i++ ){for( let j = 0 ; j<7 ; j++ ){this.data.dateArr.push(i*7+j)}}this.setData({dateArr:this.data.dateArr})},methods:{//獲取下一個月份add:function(){this.triggerEvent("addone")this.setData({dateArr: []})if (this.data.currentMonth==12 ){this.setData({currentMonth: 1,year:this.data.year+1})}else{this.setData({currentMonth: this.data.currentMonth + 1})}let currentMonthDay = this.data.year + "-" + this.data.currentMonth + "-01"let weekStr = ""this.setData({weekNum: new Date(currentMonthDay).getDay(),rowNum: Math.ceil((this.data.yearMonth[this.data.currentMonth-1] + new Date(currentMonthDay).getDay()) / 7)})for (let i = 0; i < this.data.rowNum; i++) {for (let j = 0; j < 7; j++) {this.data.dateArr.push(i * 7 + j)}}this.setData({dateArr: this.data.dateArr})},//獲取上一個月份reduce:function(){this.triggerEvent("reduceone")this.setData({dateArr:[]})if (this.data.currentMonth == 1) {this.setData({currentMonth: 12,year: this.data.year - 1})} else {this.setData({currentMonth: this.data.currentMonth - 1})}let currentMonthDay = this.data.year + "-" + this.data.currentMonth + "-01"let weekStr = ""this.setData({weekNum: new Date(currentMonthDay).getDay(),rowNum: Math.ceil((this.data.yearMonth[this.data.currentMonth-1] + new Date(currentMonthDay).getDay()) / 7)})for (let i = 0; i < this.data.rowNum; i++) {for (let j = 0; j < 7; j++) {this.data.dateArr.push(i * 7 + j)}}this.setData({dateArr: this.data.dateArr})console.log(this.data.dateArr)}}})            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 喜德县| 阿尔山市| 松滋市| 广元市| 营山县| 宣城市| 盘锦市| 寻甸| 乌拉特中旗| 崇义县| 师宗县| 遵义市| 高邮市| 蒙阴县| 通许县| 吴江市| 韩城市| 凤台县| 南开区| 凭祥市| 汾西县| 章丘市| 玉屏| 五常市| 霞浦县| 东平县| 晋宁县| 三亚市| 灵川县| 墨脱县| 滨海县| 叶城县| 黔南| 美姑县| 东平县| 兴化市| 崇义县| 阿鲁科尔沁旗| 南宁市| 林周县| 依安县|