1. 首页 > 快讯

vue移动端日历(vue日期组件)

vue-material-year-calendar 插件 activedates.push(dateinfo)后日历未选中问题解析

vue-material-year-calendar 插件中,在调用 activedates.push(dateinfo) 方法后,日历却不显示选中状态。这是因为在 vue 2 中,这种方法不会触发响应式更新,从而导致日历无法更新选中状态。

vue 2解决方案:

将 :activedates.sync 语法更改为 :activedates。

立即学习“前端免费学习笔记(深入)”;

<yearcalendar
  v-model="year"
  :activedates="activedates"
  @toggledate="toggledate"
  prefixclass="your_customized_wrapper_class"
  :activeclass="activeclass"
/>
登录后复制

vue 3解决方案:

vue 3 中提供了 ref 来实现响应式。

// ... 省略代码 ...

const activeDates = ref([
  { date: '2024-02-13', selected: true, className: '' },
  { date: '2024-02-14', className: 'red' },
  { date: '2024-02-15', className: 'blue' },
  { date: '2024-02-16', className: 'your_customized_classname' }
])
登录后复制

通过使用 ref,vue 3 能够在 activedates 数组更改时触发响应式更新,从而更新日历中的选中状态。

本文采摘于网络,不代表本站立场,转载联系作者并注明出处:https://www.iotsj.com//kuaixun/7075.html

联系我们

在线咨询:点击这里给我发消息

微信号:666666