赞
踩
1.可以发现,页面上选择的只有日期,但是代码中却有 HH:mm:ss
value-format="yyyy-MM-dd HH:mm:ss"
2.而且代码中
type="date"
3.date.getHours is not a function应该与此有关
解决方案:
删除HH:mm:ss
经验证,可以正常的选择日期了。
.
拓展:
如果想要 type="date" 页面上只展示日期 ,而向后端发送的时候是 yyyy-MM-dd HH:mm:ss 这种格式的话
- <el-date-picker
- :disabled="disabledFields.includes('battery_factory_date') && isRequired"
- class="common-datetime-picker no-close"
- popper-class="common-datetime-picker-select"
- type="date"
- placeholder="请选择"
- v-model="form.battery_factory_date"
- :picker-options="setDisabled"
- @change="getdatatime()"
- />
需要引入:
import { parseTime} from "@/utils/index";
utils/index文件
- /**
- * Parse the time to string
- * @param {(Object|string|number)} time
- * @param {string} cFormat
- * @returns {string | null}
- */
- export function parseTime(time, cFormat) {
- if (arguments.length === 0 || !time) {
- return null
- }
- const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
- let date
- if (typeof time === 'object') {
- date = time
- } else {
- if ((typeof time === 'string')) {
- if ((/^[0-9]+$/.test(time))) {
- // support "1548221490638"
- time = parseInt(time)
- } else {
- // support safari
- // https://stackoverflow.com/questions/4310953/invalid-date-in-safari
- time = time.replace(new RegExp(/-/gm), '/')
- }
- }
-
- if ((typeof time === 'number') && (time.toString().length === 10)) {
- time = time * 1000
- }
- date = new Date(time)
- }
- const formatObj = {
- y: date.getFullYear(),
- m: date.getMonth() + 1,
- d: date.getDate(),
- h: date.getHours(),
- i: date.getMinutes(),
- s: date.getSeconds(),
- a: date.getDay()
- }
- const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
- const value = formatObj[key]
- // Note: getDay() returns 0 on Sunday
- if (key === 'a') {
- return ['日', '一', '二', '三', '四', '五', '六'][value]
- }
- return value.toString().padStart(2, '0')
- })
- return time_str
- }
methods 中 :
- getdatatime(value) {
- if (value == '') {
- this.form.battery_factory_date= "";
- } else {
- this.form.battery_factory_date =
- parseTime(this.form.battery_factory_date, "{y}-{m}-{d}") + " 00:00:00";
- }
- },
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。