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>
相关推荐
AnalogElectronic4 小时前
uniapp学习5,兼容微信小程序的俄罗斯方块游戏
学习·微信小程序·uni-app
AnalogElectronic10 小时前
uniapp学习6,滚动字幕播报
javascript·学习·uni-app
AnalogElectronic10 小时前
uniapp学习3,简易记事本
学习·uni-app
Можно11 小时前
uni-app 三端上线全流程指南:H5 / 小程序 / App 完整发布手册
小程序·uni-app
2501_9151063213 小时前
Flutter 开发工具有哪些 跨平台项目开发与上架实操指南
android·flutter·ios·小程序·uni-app·iphone·webview
AnalogElectronic13 小时前
uniapp学习7,美团闪购生鲜蔬菜商家详情页
javascript·学习·uni-app
AnalogElectronic13 小时前
uniapp学习4,简易记事本2.0
学习·uni-app
小旋风0123413 小时前
uniapp开发app解决视频层级太高的问题(subNvue方法)
前端·uni-app·音视频
00后程序员张20 小时前
从审核被拒到稳定过审,iOS 上架技术优化
android·ios·小程序·https·uni-app·iphone·webview
洗发水很好用1 天前
uniapp纯css实现基础多选组件
前端·css·uni-app