Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sz861128 opened this issue Mar 1, 2023 · 0 comments
Open

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

sz861128 opened this issue Mar 1, 2023 · 0 comments

Comments

@sz861128
Copy link

sz861128 commented Mar 1, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant