Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
动机
假设现在有一个需求,我们的
ListItem
具有触发 PopUp 的能力。有两种方式可以做到:ListItem
中声明Popup
,通过wx:if
来做到性能优化。ListItem
的父组件,比如List
中声明,通过在ListItem
中triggerEvent
来发生PopUp
所需要的数据。第二种方式目前常用的方式,因为如果直接用
wx:if
判断的话,关闭Popup
时没有动画,导致整个过程很生硬。而现有的生命周期又不满足需求,所以通过在transtion
后,将wx:if
改为 false 就能拿到效果。虽然我们可以继续使用第二种方式,但是它很容易让
List
变成一个非常庞大的组件。这里有一个Popup
,那里又有一个Popup
,不知不觉就变成了PopUp
中转站。所以,通过添加这个事件,可以在一定程序上减少对List
的依赖。更关注ListItem
本身。