mint ui 时间选择器的使用

主要功能:
  • 实现两个时间选择器
  • 手机端屏蔽键盘
  • 数据回显

H5代码

<li class="input-line g-arrow-r">
                            <label>开始时间</label>
                            <div class="input-box">
                                <span @click="openPicker(0)" class="picker">{{form.date1 ? form.date1 : '请选择'}}</span>
                                <mt-datetime-picker
                                        v-model="pickerVisible"
                                        ref="start"
                                        type="datetime"
                                        month-format="{value} 月"
                                        date-format="{value} 日"
                                        hour-format="{value} 时"
                                        minute-format="{value} 分"
                                        :startDate="startDate"
                                        :editable=false
                                        @confirm="handleConfirm(0)">
                                </mt-datetime-picker>
                            </div>
                        </li>
                        <!--结束时间-->
                        <li class="input-line g-arrow-r">
                            <label>结束时间</label>
                            <div class="input-box">
                                <span @click="openPicker(1)" class="picker">{{form.date2 ? form.date2 : '请选择'}}</span>
                                <mt-datetime-picker
                                        v-model="pickerVisible"
                                        ref="end"
                                        type="datetime"
                                        month-format="{value} 月"
                                        date-format="{value} 日"
                                        hour-format="{value} 时"
                                        minute-format="{value} 分"
                                        :startDate="startDate"
                                        :editable=false
                                        @confirm="handleConfirm(1)">
                                </mt-datetime-picker>
                            </div>
                        </li>

JS代码

// 打开时间选择器
            openPicker(item) {
                // 设置默认开始时间
                this.pickerVisible = new Date();
                if (item === 0) {
                    this.$refs.start.open()
                } else {
                    this.$refs.end.open()
                }
            },
            // 时间选择器确定按钮
            handleConfirm(item) {
                // console.log(this.pickerVisible);
                if (this.pickerVisible !== "") {
                    if (item === 0) {
                        this.form.date1 = dateFormat(this.pickerVisible);
                    } else {
                        this.form.date2 = dateFormat(this.pickerVisible);
                    }
                }
            },

picker样式文件

<style scoped>
    .picker{
        height:21px;
        width:100%;
        display:block
    }
</style>

实现的效果
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值