Skip to content

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

Open
@sz861128

Description

@sz861128

由于设置 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 但无效,还望指点!谢谢

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions