web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. AIGC工具
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站
    手机应用

element-ui时间组件el-date-picker用x清空后报错解决方法

2390 ℃

问题描述:今天测试el-date-picker时间组件type="datetimerange"时,发现点击X清空图标,报vue.esm.js?efeb:628 [Vue warn]: Error in v-on handler: "TypeError: Cannot read properties of null (reading '0')",后来发现没对value做判断。

问题分析:在使用DatePicker日期选择器选择日期范围的时候,会用到一个属性clearable。这个属性是Boolean变量,用于决定是否显示清除按钮,默认为true。 当点击清除按钮的时候,value会被设置为null。所以会报错

解决方法:

//引入@change="getMyDateTime()"方法

<el-date-picker
  v-model="searchForm.dateTime"
  type="datetimerange"
  align="right"
  unlink-panels
  range-separator="至"
  :start-placeholder="searchForm.startDate"
  :end-placeholder="searchForm.endDate"
  :picker-options="pickerOptions"
  format="yyyy-MM-dd"
  value-format="yyyy-MM-dd"
  @change="getMyDateTime()"
></el-date-picker>

getMyDateTime加判断

getMyDateTime() {
  const _this = this.searchForm;
  _this.startDate = _this.dateTime ? _this.dateTime[0] : dataTime.getBeforeDate(30);
  _this.endDate = _this.dateTime ? _this.dateTime[1] : dataTime.getBeforeDate(0);
}

//设置dataTime.getBeforeDate是因为项目的默认时间是30天区间,如果不需要可以用""代替

el-time-picker设置默认赋值时间

Vue项目如何实现文件上传(附完整代码)

Vue开发中最常用的几种UI组件库

vue语法如何设置el-select默认值

el-tree组件如何添加虚线指示

标签: clearable, el-date-picker, element-ui, 时间, 时间控件, 时间组件

上面是“element-ui时间组件el-date-picker用x清空后报错解决方法”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_2323.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > vuejs
本文共计904个字,预计阅读时长7分钟
Trae:新一代免费的AI编程工具

基金从业资格考试题库

一站式备考基金从业资格考试,收录2021-2025年模拟题库!呱呱工具箱

AI工作站

收录全球3800+ 款各行各业AI应用,轻轻松松做事!
生活小工具,收录了80多款小工具
上一篇: 一键生成脚本与分镜,激发无限创意的一款AI故事生成助手——OneStory
下一篇: 一款专注于语音合成和音色克隆服务的AI语音工具——MiniMax Audio
x 打工人ai神器