b2nil / taro-ui-vue3

采用 Vue 3.0 重写的 Taro UI 组件库
https://b2nil.github.io/taro-ui-vue3/
MIT License
160 stars 51 forks source link

Calendar 组件不能选取日期 #4

Closed b2nil closed 4 years ago

b2nil commented 4 years ago

日历组件无法选取日期。

排查问题时发现:

问题复现 repo: taro-vue3-calendar

b2nil commented 4 years ago

已修复: 267c62614512bcc27c17d554b92550923cb685ec

具体原因: 日期列表渲染时,handleClick 函数没有绑定在当前的日期item上,导致点击事件传播至日期列表中的每一个日期,造成死循环。

在这一点上,采用 render function 与采用 template 存在区别,template 无需使用 bind

props.list.map((item: Calendar.Item, index: number) => {
  return h(CommonView, {
           key: `list-item-${item.value}-${index}`,
           onTap: handleClick(item),  //应为 handleClick.bind(this, item)
           onLongPress: handleLongClick(item), //应为 handleLongClick.bind(this, item)
           class: genDateItemClass(item)
  }, [...]