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

fix: 添加 passive 事件监听器以提高页面滚动性能 #688

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
</scroll-view>
<view
class="wd-index-bar__sidebar"
@touchstart.stop.prevent="handleTouchStart"
@touchmove.stop.prevent="handleTouchMove"
@touchstart.stop.passive.prevent="handleTouchStart"
@touchmove.stop.passive.prevent="handleTouchMove"
Comment on lines +11 to +12
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

注意:.passive.prevent 修饰符的冲突问题

当前的事件监听器同时使用了 .passive.prevent 修饰符,这两个修饰符是互相矛盾的:

  • .passive 告诉浏览器事件处理程序不会调用 preventDefault()
  • .prevent 会调用 preventDefault()
  • 这种组合会导致 .passive 失去提升性能的作用

建议根据实际需求选择其中之一:

如果需要阻止默认行为:

-@touchstart.stop.passive.prevent="handleTouchStart"
-@touchmove.stop.passive.prevent="handleTouchMove"
+@touchstart.stop.prevent="handleTouchStart"
+@touchmove.stop.prevent="handleTouchMove"

如果想提升滚动性能:

-@touchstart.stop.passive.prevent="handleTouchStart"
-@touchmove.stop.passive.prevent="handleTouchMove"
+@touchstart.stop.passive="handleTouchStart"
+@touchmove.stop.passive="handleTouchMove"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@touchstart.stop.passive.prevent="handleTouchStart"
@touchmove.stop.passive.prevent="handleTouchMove"
@touchstart.stop.prevent="handleTouchStart"
@touchmove.stop.prevent="handleTouchMove"
```
Option 2 (if improving scroll performance is needed):
```suggestion
@touchstart.stop.passive="handleTouchStart"
@touchmove.stop.passive="handleTouchMove"

@touchend.stop.prevent="handleTouchEnd"
@touchcancel.stop.prevent="handleTouchEnd"
>
Expand Down