2***@qq.com
2***@qq.com
  • 发布:2025-10-30 16:22
  • 更新:2025-10-30 16:28
  • 阅读:55

preventDefault和stopPropagation编译成微信小程序无法使用

分类:uni-app

@touchmove="handleTouchMove($event, index)"

function handleTouchMove(event, index) {
if (xxxx) {
//代码逻辑
} else {
event.preventDefault();
event.stopPropagation();
//代码逻辑
}
}

编译成微信小程序后并没有阻止原生事件, 以及事件冒泡

如果使用.stop修饰符, 则无法进行条件判断, 直接给原生事件一刀切了, 导致屏幕无法滚动

而想实现的效果是, 在一些条件下阻止原生事件不让滚动, 另一些条件下是可以滚动的

2025-10-30 16:22 负责人:无 分享
已邀请:
DCloud_UNI_JBB

DCloud_UNI_JBB

使用.stop修饰符有什么问题?

  • 2***@qq.com (作者)

    使用.stop是写死的, 没办法根据业务动态的阻止冒泡

    2025-10-30 16:34

  • DCloud_UNI_JBB

    回复 2***@qq.com: 微信有限制

    2025-10-30 16:39

  • 2***@qq.com (作者)

    回复 DCloud_UNI_JBB: 微信小程序没有办法动态的阻止原生事件吗

    2025-10-30 17:16

  • DCloud_UNI_JBB

    回复 2***@qq.com: 文档上没找到,你也可以查找一下

    2025-10-30 17:27

  • DCloud_UNI_JBB

    回复 2***@qq.com: https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/event.html#%E4%BA%92%E6%96%A5%E4%BA%8B%E4%BB%B6%E7%BB%91%E5%AE%9A 这个能满足你的需求吗?

    2025-10-30 20:32

  • 2***@qq.com (作者)

    回复 DCloud_UNI_JBB: 满足不了, 我改成wsx语法吧, 谢谢你啦

    2025-10-31 10:39

要回复问题请先登录注册