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

useDrop isOver在进入放置目标时会变化两次? #61

Closed
xia0ming opened this issue Oct 9, 2023 · 4 comments
Closed

useDrop isOver在进入放置目标时会变化两次? #61

xia0ming opened this issue Oct 9, 2023 · 4 comments

Comments

@xia0ming
Copy link

xia0ming commented Oct 9, 2023

拖动元素进入放置目标(无嵌套)时, isOver会进行true -> false -> true的变化

const [dropCollect, drop] = useDrop({
    accept: ['BOX'],
    collect: monitor => ({
      isOver: monitor.isOver({ shallow: true })
    })
  })

const { isOver } = toRefs(dropCollect)

watch(isOver, val => {
  console.log('val')
})

// true
// false
// true

拖动进入时, 会打印true -> false -> true
请教是什么原因呢

@xia0ming
Copy link
Author

xia0ming commented Oct 9, 2023

其实需求是没有成功放置的回调
放置成功后的逻辑在useDrop中drop回调内,
如果是没有成功放置(拖到到其他非目标区域松开鼠标)有办法执行回调么

@hcg1023
Copy link
Owner

hcg1023 commented Oct 9, 2023

其实需求是没有成功放置的回调 放置成功后的逻辑在useDrop中drop回调内, 如果是没有成功放置(拖到到其他非目标区域松开鼠标)有办法执行回调么

可以使用useDragend事件,通过monitor.didDrop()来判断拖拽是否被处理

@xia0ming
Copy link
Author

xia0ming commented Oct 9, 2023

查了一下, isOver的问题react-dnd也存在, 而且暂时还没有修复
react-dnd/react-dnd#3489

@xia0ming
Copy link
Author

xia0ming commented Oct 9, 2023

其实需求是没有成功放置的回调 放置成功后的逻辑在useDrop中drop回调内, 如果是没有成功放置(拖到到其他非目标区域松开鼠标)有办法执行回调么

可以使用useDragend事件,通过monitor.didDrop()来判断拖拽是否被处理

我试试, 蟹蟹大佬回复

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

2 participants