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

列表渲染中阻止冒泡事件报错 #3946

Closed
lhzbxx opened this issue Jul 25, 2019 · 7 comments
Closed

列表渲染中阻止冒泡事件报错 #3946

lhzbxx opened this issue Jul 25, 2019 · 7 comments
Assignees

Comments

@lhzbxx
Copy link

lhzbxx commented Jul 25, 2019

问题描述
在列表渲染的情况下,尝试用 e.stopPropagation() 阻止冒泡,提示 e.stopPropagation is not a function。
尝试用 #761 (comment) 的方法包装一层 View,但是仅在列表中只有一个元素的时候不报错,其他情况下依旧报错。

复现步骤

{list.map((i, index) => (
  <View
    className="item"
    key={i.label}
    onClick={() => onClick && onClick(index, false)}
  >
    <Text className="label">{i.label}</Text>
    <View onClick={(e) => e.stopPropagation()}>
      <Image
        className="icon"
        src={closeSVG}
        onClick={(e) =>
          closeable &&
          onClick &&
          onClick(index, true)
          // e.stopPropagation()
        }
      />
    </View>
  </View>
))}

期望行为

使用 e.stopPropagation() 不报错的情况下阻止冒泡。

报错信息

thirdScriptError
e.stopPropagation is not a function; [Component] Event Handler Error @ components/auto-complete/index#(anonymous)
TypeError: e.stopPropagation is not a function

系统信息

Taro CLI 1.3.9 environment info:
System:
OS: macOS 10.14.5
Shell: 5.3 - /bin/zsh
Binaries:
Node: 12.1.0 - /usr/local/bin/node
Yarn: 1.15.2 - /usr/local/bin/yarn
npm: 6.10.1 - /usr/local/bin/npm
npmGlobalPackages:
typescript: 2.5.3

@taro-bot
Copy link

taro-bot bot commented Jul 25, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@lhzbxx lhzbxx changed the title 列表渲染中阻止冒泡事件失败 列表渲染中阻止冒泡事件报错 Jul 25, 2019
@yuche
Copy link
Contributor

yuche commented Jul 25, 2019

你打印下看 e 是什么

@lhzbxx
Copy link
Author

lhzbxx commented Jul 25, 2019

你打印下看 e 是什么

e 是正常的,包含了 stopPropagation 函数,且 typeof e.stopPropagation === 'function'。

changedTouches: [{}]
currentTarget: {id: "", offsetLeft: 325, offsetTop: 151, dataset: {}, x: 352.33984375,}
detail: {x: 352.33984375, y: 174.95703125}
mark: {}
preventDefault: ƒ ()
stopPropagation: ƒ ()
target: {id: "", offsetLeft: 325, offsetTop: 151, dataset: {}, x: 352.33984375,}
timeStamp: 5138
touches: [{}]
type: "tap"

@yuche
Copy link
Contributor

yuche commented Jul 25, 2019

你打印的地方同时也是你报错的地方吗

@lhzbxx
Copy link
Author

lhzbxx commented Jul 25, 2019

你打印的地方同时也是你报错的地方吗

当然,是写在一起的,确实很诡异。

@yycang
Copy link

yycang commented Jul 25, 2019

同样遇到错误

@yuche yuche self-assigned this Jul 25, 2019
@yuche yuche closed this as completed in 5b02527 Jul 26, 2019
@Jinxhao18
Copy link

taro 2.6.0 e[0].stopPrapagation();可以阻止冒泡,event是个数组

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

4 participants