element el-date-picker 去除自带的T格式
Posted 修仙之路灵根中等
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了element el-date-picker 去除自带的T格式相关的知识,希望对你有一定的参考价值。
<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格式的主要内容,如果未能解决你的问题,请参考以下文章
vue element el-date-picker设置当日之前/之后的日期不可选择
element-ui日期控件el-date-picker显示的月份、日期由英文改为中文
2020-06-30 关于element-ui中el-date-picker组件时间落后8个小时的问题
element el-date-picker 插件默认时间属性default-value怎么赋值
vue知识点---element el-date-picker 插件默认时间属性default-value怎么赋值?
element 时间日期选择器el-date-picker点击清空按钮报错:TypeError: Cannot read properties of null (reading '0'