Hzy0913 / mpvue-calendar

📅 A calendar component for vue3.0. Support gesture sliding, range selection, according to the week switch...
http://preview.binlive.cn/mpvue-calendar#/
MIT License
514 stars 105 forks source link

请问monthRange参数如何设置为响应? #141

Open sz861128 opened 1 year ago

sz861128 commented 1 year ago

由于设置 mode="monthRange" 就没有左右按钮了,所以尝试自己写了一个,代码如下:

const monthRange = ref(['2021-2', '2021-3'])
const changeDate = (data, direction) => {
  let dataArray = []
  data.forEach(item => {
    let year = item.slice(0, item.indexOf('-'))
    let month = item.slice(item.indexOf('-') + 1)
    if (direction == 'prev') {
      month = parseInt(month) - 1
      if (month < 1) {
        month = 12
        year = parseInt(year) - 1
      }
    } else {
      month = parseInt(month) + 1
      if (month > 12) {
        month = 1
        year = parseInt(year) + 1
      }
    }
    dataArray.push(year + '-' + month)
  })
  return dataArray
}
// 上一个月
const prev = () => {
  monthRange.value = changeDate(monthRange.value, 'prev')
}
// 下一个月
const next = () => {
  monthRange.value = changeDate(monthRange.value, 'next')
}

但是 monthRange 无法响应到视图,请问如何能做到响应呢? 以尝试用 nextTick 但无效,还望指点!谢谢