Vue 用Vant实现时间选择器的示例代码

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Vue 用Vant实现时间选择器的示例代码

honey缘木鱼   2020-05-17 我要评论

1.查看Vant官网https://youzan.github.io/vant/

引入Vant中DatetimePicker组件(全局引入后可直接使用)

import Vue from 'vue';
import { DatetimePicker } from 'vant'
Vue.use(DatetimePicker);

关键使用代码(结合vant组件Popup的底部弹出层一起使用)

<van-popup v-model="dateShow" position="bottom">
   <van-datetime-picker v-model="currentDate" type="year-month" @cancel="handleCancel"
    @confirm="handleEndDateConfirm" />
  </van-popup>

export default {
 data() {
  return {
   dateShow: false,
   currentDate: new Date()
  };
 }
}

效果图

实现点击确定 和取消的方法

handleCancel () {
   this.dateShow = false;
  },
  //开始时间
  handleEndDateConfirm () {
   this.dateShow = false;
   this.titleTime = dateFormat(this.currentDate, 'yyyy-MM')
  },

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们