vue el-date-picker 日期选择 回显后成功后无法改变的解决办法

在实现一个前端页面默认时间选择时遇到了手动选择日期无法回显但在浏览器vue插件监控属性时却能看到手动选择的值的问题。

html 复制代码
<el-date-picker
  v-else-if="item.type === 'datetPicker'"
  v-model="form[item.prop]"
  :placeholder="item.placeholder"
  :picker-options="item.pickerOptions"
  type="date"
  value-format="yyyy-MM-dd"
  clearable
/>

在钩子函数默认选择昨天

js 复制代码
  created() {
    this.defaultDate()
  }
  defaultDate() {
     let date = new Date();
     const yesterday = date.setDate(date.getDate() - 1);
     this.form.startDate = this.handleTime(yesterday)
     this.form.endDate = this.handleTime(yesterday)
   },
   handleTime(yesterday) {
     let date = new Date(yesterday);
     const year = date.getFullYear();
     // 获取月份,要加 1,格式化为两位数
     const month = String(date.getMonth() + 1).padStart(2, '0');
     // 获取日期,格式化为两位数
     const day = String(date.getDate()).padStart(2, '0');
     const res = year + '-' + month + '-' + day;
     this.$set(this.form,'startDate', res)
     this.$set(this.form,'endDate', res)
     return res;
   }

加上这两行代码就能解决上述问题了。

js 复制代码
this.$set(this.form,'startDate', res)
this.$set(this.form,'endDate', res)
相关推荐
Ruihong3 分钟前
Vue 转 React:揭秘 scoped 样式是如何被 VuReact 编译的?
vue.js·react.js·面试
胖纳特5 分钟前
从零到一:OnlyOffice中国版企业级完整落地指南
前端·后端
MiNG MENS9 分钟前
Spring Boot + Vue 全栈开发实战指南
vue.js·spring boot·后端
Ruihong9 分钟前
Vue 组件样式 <style> 转 React:VuReact 怎么处理?
vue.js·react.js·面试
jrlong9 分钟前
HelloAgents 进阶篇 task03
java·前端·python
搬砖的前端10 分钟前
本地模型+TRAE CN 打造最优模型组合实测:开源主模型+本地辅模型,对标GPT5.2/5.3/Gemini-3-Flash
前端·ai·mac·ai编程·qwen·trae·qwen3.6
userxxcc12 分钟前
Waigo是用“Golang+Web”写的“视图窗口+稳定服务”的桌面端(Win、Mac、Ubuntu)多功能程序基座。开箱即用但有一定上手门槛。
javascript·golang·桌面应用基座·wails3
talen_hx29614 分钟前
飞书机器人发文本消息
java·前端·飞书
freewlt19 分钟前
前端工程化性能监控体系建设:从0到1实战指南
前端
Mintopia20 分钟前
别再一上来就分层:新手最容易做错的系统设计决定
前端