uniapp自带的选择日期的使用

年月日的下拉框

直接看代码

javascript 复制代码
<view class="uni-title uni-common-pl">日期选择器</view>
		<view class="uni-list">
			<view class="uni-list-cell">
				<view class="uni-list-cell-left">
					当前选择
				</view>
				<view class="uni-list-cell-db">
					<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
						<view class="uni-input">{{date}}</view>
					</picker>
				</view>
			</view>
		</view>
	<script>
export default {
    data() {
        const currentDate = this.getDate({
            format: true
        })
        return {
            date: currentDate,//默认设置的时间 此处可以从后台获取
        }
    },
    computed: {
        startDate() {
            return this.getDate('start');
        },
        endDate() {
            return this.getDate('end');
        }
    },
    methods: {
  
        bindDateChange: function(e) {
            this.date = e.detail.value
        },
        
        //获取当前的日子
        getDate(type) {
            const date = new Date();
            let year = date.getFullYear();
            let month = date.getMonth() + 1;
            let day = date.getDate();

            if (type === 'start') {
                year = year - 60;
            } else if (type === 'end') {
                year = year + 2;
            }
            month = month > 9 ? month : '0' + month;
            day = day > 9 ? day : '0' + day;
            return `${year}-${month}-${day}`;
        }
    }
}
</script>
相关推荐
2501_915921433 小时前
没有Mac如何完成iOS 上架:iOS App 上架App Store流程
android·ios·小程序·https·uni-app·iphone·webview
玩代码的菜鸟5 小时前
uniapp类似抖音视频滑动
uni-app
默魔13 小时前
uniapp 微信小程序点击开始倒计时
微信小程序·小程序·uni-app
shmily ....1 天前
医疗预约系统中的录音与图片上传功能实现:Vue3+Uniapp 实战
uni-app
小阿技术1 天前
uniapp制作一个个人页面
uni-app
小阿技术1 天前
uniapp制作一个视频播放页面
uni-app
小周同学:1 天前
uni-app获取手机当前连接的WIFI名称
智能手机·uni-app
书山有路勤为径~2 天前
【解决问题】HBuilderX窗口文字太小
uni-app
qq_424409192 天前
uniapp的app项目,某个页面长时间无操作,返回首页
前端·vue.js·uni-app
2501_915918412 天前
Fiddler中文版全面评测:功能亮点、使用场景与中文网资源整合指南
android·ios·小程序·https·uni-app·iphone·webview