zoukankan      html  css  js  c++  java
  • 时间选择器datetimerpicker封装使用(非脚手架)

    datePicker.vue 封装

    <template>
        <el-date-picker
                v-model="currentTime"
                type="datetimerange"
                :picker-options="pickerOptions"
                range-separator="~"
                format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                align="right"
                @change="getChorceTime">
        </el-date-picker>
    </template>
    
    <script>
    
        module.exports = {
            name: "datePicker",
            props: ['time'],
            data() {
                return {
                    currentTime: "",
                    pickerOptions: {
                        shortcuts: [
                            {
                                text: '最近一周',
                                onClick(picker) {
                                    const end = new Date();
                                    const start = new Date();
                                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                                    picker.$emit('pick', [start, end]);
                                }
                            }, {
                                text: '最近一个月',
                                onClick(picker) {
                                    const end = new Date();
                                    const start = new Date();
                                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                                    picker.$emit('pick', [start, end]);
                                }
                            }, {
                                text: '最近三个月',
                                onClick(picker) {
                                    const end = new Date();
                                    const start = new Date();
                                    start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                                    picker.$emit('pick', [start, end]);
                                }
                            }]
                    },
                }
            },
            methods:{
                getChorceTime(val){
                    if(val == null){
                        bus.$emit('changeTimeValue',"");
                    }else{
                        bus.$emit('changeTimeValue',val)
                    }
                }
            }
        }
    </script>
    
    <style scoped>
    
    </style>

    注意:

     value-format :一定要,否则选择的时间是带有英文月份的时间,不是想要的年月日时分秒

     
    getChorceTime(val){
                    if(val == null){
                        bus.$emit('changeTimeValue',""); // 必要:当交互中清除已选时间时查询条件应该清空
                    }else{
                        bus.$emit('changeTimeValue',val) // 传递当前选择的时间
    } }
     

    使用

    js.
    module.exports = { name:'FileUpload', components: { 'date-picker': httpVueLoader('/template/default/pc/home/index/components/datePicker.vue'), },
    }

    <template>

    <date-picker :time="searchForm.time"></date-picker>
    </template>
    
    
    核心:
    mounted(){ bus.$on(
    'changeTimeValue',(val)=>{ if(val){ this.searchForm.time = val[0] + '~' + val[1]; }else{ this.searchForm.time = ""; } }) }
     

    本文来自博客园,作者:💞Travelerᘗ,转载请注明原文链接:https://www.cnblogs.com/LindaBlog/p/15791230.html

  • 相关阅读:
    为Jboss4配置数据库
    从JAVA源代码到EXE可执行文件
    连接数据库出现:Connections could not be acquired from the underlying database
    SVN修改用户名与密码
    linux 下开放指定端口
    Nginx 禁止IP访问及未绑定的域名跳转
    Proguard混淆后无法正常运行的问题:
    How To Automate Internet Explorer to POST Form Data
    poj 2667 hotel 线段树
    poj 3691 DNA repair AC自动机+DP
  • 原文地址:https://www.cnblogs.com/LindaBlog/p/15791230.html
Copyright © 2011-2022 走看看