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>
相关推荐
阿奇__10 小时前
uniapp支付宝 H5 开发踩坑,hash模式下取参要规范!
开发语言·uni-app
云起SAAS13 小时前
小智笔记APP源码 | 8大广告联盟聚合(穿山甲/优量汇/快手/百度) | 应用市场过审极速版 | uni-app全栈商用项目
笔记·uni-app·广告联盟·笔记app
蹦哒16 小时前
UniApp 原生插件开发完整指南
uni-app
a_Ichuan16 小时前
在HBuilderX创建的uniapp项目中使用unocss
前端·uni-app
web前端神器16 小时前
记录uniapp小程序的报错
小程序·uni-app·apache
yqcoder18 小时前
uni-app 之 网络请求
网络·uni-app
克里斯蒂亚诺更新18 小时前
uniapp适配H5和Android-apk实现获取当前位置经纬度并调用接口
android·前端·uni-app
2501_916008891 天前
深入解析iOS应用启动性能优化策略与实践
android·ios·性能优化·小程序·uni-app·cocoa·iphone
巴巴博一2 天前
uni-app 踩坑实录:实现“可拖拽全局悬浮按钮”时的 movable-view 坐标失效与 Flex 布局视错觉
vue.js·uni-app
阿奇__2 天前
h5微信授权code失效排查过程及解决记录
微信·uni-app