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>
相关推荐
笨笨狗吞噬者15 小时前
记录一个uniapp小程序端编译时问题
前端·微信小程序·uni-app
会一丢丢蝶泳的咻狗2 天前
uni-app安卓端强制更新apk包
android·前端·uni-app
iOS阿玮2 天前
苹果审核被拒,其实可以靠回复也能过审
uni-app·app·apple
程序员小刘2 天前
HarmonyOS 5中UniApp的调试步骤
华为·uni-app·harmonyos
饭啦啦2 天前
uniapp音乐播放createInnerAudioContext
uni-app
米粒宝的爸爸2 天前
uniapp中vue3 ,uview-plus使用!
前端·vue.js·uni-app
狂龙骄子2 天前
uniapp Switch控件背景颜色自定义
css·uni-app·switch·hbuilderx·colorui
qq_424409192 天前
uniapp的app项目,在华为pad上运行,页面显示异常
uni-app
涛々2 天前
uniapp-vue3-js-vite-pinia-eslint 快速开发模板
javascript·uni-app·uniapp+vue3模板
三天不学习2 天前
使用Cursor + Devbox + Uniapp 一站式AI编程开发移动端(App、H5、小程序)
小程序·uni-app·ai编程