欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2018年12月29日 08:31:56   作者:dahuworld  
這篇文章主要為大家詳細介紹了微信小程序日歷組件的使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下

這個日歷采用小程序組件化開發(fā),有興趣的同學可以引用本組件(怎么引用不多贅述,自行去微信小程序開發(fā)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.js
Component({
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)
}
}
})

wxss

/* pages/components/calender.wxss */
.operate{
width:100%;
display: flex;
flex-direction: row;
justify-content: space-around;
font-size: 32rpx;
color:#000;
padding-bottom: 40rpx;
}
.year{
padding:0 30%;
display: flex;
flex-direction: row;
justify-content: space-around;
font-size:32rpx;
color:#404040;
margin-bottom: 40rpx;
}
.calender{
display: flex;
flex-direction: column;
padding:0 4.5%;
width:91%;
border-top:1rpx solid #eaeaea;
padding-top:30rpx;
color:#404040;
}
.calender .week{
display: flex;
flex-direction: row;
}
.calender .week text{
width:14%;
text-align: center;
font-size:26rpx;
}
.calender .date text{
width:14%;
display: inline-block;
text-align: center;
font-size:26rpx;
color:#000;
}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • 淺析JavaScript中預編譯的原理與流程

    淺析JavaScript中預編譯的原理與流程

    這篇文章主要為大家詳細介紹了JavaScript中預編譯的原理與流程的相關知識,文中的示例代碼講解詳細,對我們深入了解JavaScript有一定的幫助,感興趣的小伙伴可以跟隨小編一起學習一下
    2023-10-10
  • Javascript小技能總結(推薦)

    Javascript小技能總結(推薦)

    本文是小編日常收集整理的有個js中的一些小技能,非常實用,值得推薦給大家,感興趣的朋友快來收藏吧
    2016-06-06
  • JavaScript Set與Map數據結構詳細分析

    JavaScript Set與Map數據結構詳細分析

    大家心里是否產生過這樣的疑問,JS中既然已經有對象這種數據結構,我們?yōu)槭裁催€要再單獨去使用Set或者Map呢?下面這篇文章主要給大家介紹了關于ES6中Set和Map數據結構的相關資料,需要的朋友可以參考下
    2022-11-11
  • javascript實現計算指定范圍內的質數示例

    javascript實現計算指定范圍內的質數示例

    這篇文章主要介紹了javascript實現計算指定范圍內的質數,涉及javascript數值計算與判斷相關操作技巧,需要的朋友可以參考下
    2018-12-12
  • Layui事件監(jiān)聽的實現(表單和數據表格)

    Layui事件監(jiān)聽的實現(表單和數據表格)

    這篇文章主要介紹了Layui事件監(jiān)聽的實現(表單和數據表格),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-10-10
  • js阻止瀏覽器默認行為觸發(fā)的通用方法(推薦)

    js阻止瀏覽器默認行為觸發(fā)的通用方法(推薦)

    下面小編就為大家?guī)硪黄猨s阻止瀏覽器默認行為觸發(fā)的通用方法(推薦)。小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-05-05
  • JS+html5 canvas實現的簡單繪制折線圖效果示例

    JS+html5 canvas實現的簡單繪制折線圖效果示例

    這篇文章主要介紹了JS+html5 canvas實現的簡單繪制折線圖效果,結合實例形式分析了js結合HTML5 canvas技術實現圖形繪制的數值運算與數組遍歷等操作技巧,需要的朋友可以參考下
    2017-03-03
  • uniapp項目實踐封裝通用請求上傳以及下載方法總結

    uniapp項目實踐封裝通用請求上傳以及下載方法總結

    在日常開發(fā)過程中,前端經常要和后端進行接口聯(lián)調,獲取并且渲染數據到頁面中,接下來就總結一下?uniapp?中獲取請求、文件下載和上傳的一些方法
    2023-09-09
  • JavaScript實現的瀏覽器下載文件的方法

    JavaScript實現的瀏覽器下載文件的方法

    本文通過一段簡單的代碼給大家介紹了js實現瀏覽器下載文件的方法,需要的的朋友參考下吧
    2017-08-08
  • javascript 動態(tài)參數判空操作

    javascript 動態(tài)參數判空操作

    在做交友中心的頁面的時候,有一個javascript函數,它的第二個參數是動態(tài)的。
    2008-12-12

最新評論