首页 > 其他 > 详细

element el-date-picker 去除自带的T格式

时间:2021-05-25 17:05:19      阅读:169      评论:0      收藏:0      [点我收藏+]
<template>
  <div>
    <el-date-picker v-model="nInput" :type="type" :placeholder="placeholder" :readonly="readonly" :disabled="disabled" :clearable="clearable" @input="salaryChange"></el-date-picker>
  </div>
</template>

<script>
import { formatTimePicker } from ‘@/utils‘
export default {
  props: {
    value: {
      type: String,
      default: ‘‘
    },
    placeholder: {
      type: String
    },
    clearable: {
      type: Boolean,
      default: false
    },
    disabled: {
      type: Boolean,
      default: false
    },
    readonly: {
      type: Boolean,
      default: false
    },
    type: {
      type: String,
      default:‘datetime‘
    }
  },
  data() {
    return {
      nInput: null
    }
  },
  watch: {
    nInput(val, oldVal) {
      let dateVal = formatTimePicker(val)
      this.$emit(‘input‘, dateVal)
    },
    value(val, oldVal) {
      this.nInput = val
    }
  },
  created() {
    this.nInput = this.value
  },
  methods: {
    salaryChange(e) {
      // console.log(e)
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
 
var formatTimePicker = function (d) { // 返回年月日时分秒
    if (d && typeof d === ‘object‘) {
        var now = d
        var year = now.getFullYear()
        var month = (now.getMonth() + 1) < 10 ? ‘0‘ + (now.getMonth() + 1) : (now.getMonth() + 1)
        var date = now.getDate() < 10 ? ‘0‘ + now.getDate() : now.getDate()
        var hour = now.getHours() < 10 ? ‘0‘ + now.getHours() : now.getHours()
        var minute = now.getMinutes() < 10 ? ‘0‘ + now.getMinutes() : now.getMinutes()
        var second = now.getSeconds() < 10 ? ‘0‘ + now.getSeconds() : now.getSeconds()
        return year + ‘-‘ + month + ‘-‘ + date + ‘ ‘ + hour + ‘:‘ + minute + ‘:‘ + second
    }
    return d
}
export {
    formatTimePicker
}

element el-date-picker 去除自带的T格式

原文:https://www.cnblogs.com/HCXiao/p/14809135.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!