寫個(gè)簡(jiǎn)單的日期選擇器,還沒搞樣式,所以有點(diǎn)丑
大概長(zhǎng)這樣吧
首先是這個(gè)picker選擇器,mode選擇日期,end是寫一個(gè)范圍前日期,:end就是這個(gè)日期是動(dòng)態(tài)變化的,還有change函數(shù)文章來源:http://www.zghlxwxcb.cn/news/detail-651359.html
<template>
<view>
<view>發(fā)生時(shí)間</view>
<picker mode="date" :end="endDate"@change="bindDateChange">
<view>{{date}}</view>
</picker>
</view>
</template>
然后是腳本,就默認(rèn)顯示當(dāng)前日期,設(shè)計(jì)最后范圍日期為今日日期,再有一個(gè)事件函數(shù)文章來源地址http://www.zghlxwxcb.cn/news/detail-651359.html
<script>
export default {
data() {
return {
date: this.getDate()
}
},
computed:{
endDate(){
return this.getDate();
}
},
methods: {
getDate() {
const date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
month = month > 9 ? month : '0' + month;
day = day > 9 ? day : '0' + day;
return `${year}-${month}-${day}`;
},
bindDateChange: function(e) {
this.date = e.detail.value;
}
}
}
</script>
到了這里,關(guān)于uni-app日期選擇器的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!