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

vue eventBus $on 多次触发 #31

Open
lovelmh13 opened this issue Apr 29, 2020 · 0 comments
Open

vue eventBus $on 多次触发 #31

lovelmh13 opened this issue Apr 29, 2020 · 0 comments

Comments

@lovelmh13
Copy link
Owner

场景

替换图片,用$on监听上传图片完成,$emit在图片上传完成以后触发。

结果

结果第一次点击,上传一次;第二次点击,上传两次;第三次点击,上传三次。

然而$emit实际只触发了一次,只是$on被触发了多次。

怀疑原因

怀疑是发布订阅的池子里,因为每一次点击图片,$emitpush进去一个uploadSuccess,但是后续触发了$on以后,并没有把池子里的uploadSuccess删掉,所以之后会触发与点击次数同等多的$on

解决

在每次$on前,先$off,清除uploadSuccess,再重新添加$on

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