-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
子组件的标签有id属性时,父组件的回调函数异常 #7317
Comments
你的子组件ID一样的话,会有这个问题,taro自己会生成一个UID,一个UID对应一个hash里面的一个事件 |
ID不一样 |
哈哈哈哈😂,和我的问题一样,搞得我都开始怀疑react了。 你说你的Child.tsx中的ID的不同,只看Child.tsx文件两个View的ID确实是不同的,但是你可能忘记了你将Child.tsx分别在index.tsx和detail.tsx中使用了且Child.tsx中的ID是写死的,这样就会导致index.tsx和detail.tsx中的 解决方案就是保证每次调用组件生成的id是不同的,需要动态生成id不能写死。我的解决方案是使用固定前缀+时间戳。如果你不需要这个id你可以不写,这样taro就会自动生成一个唯一的id 下面是调试时看到Taro位于 export function eventHandler (event: MpEvent) {
if (event.currentTarget == null) {
event.currentTarget = event.target
}
const node = document.getElementById(event.currentTarget.id)
if (node != null) {
node.dispatchEvent(createEvent(event, node))
}
} 我认为Taro应该在官方文档中注明必须保持id是全局唯一的。 |
不太好改,所有页面都挂在同一颗 DOM 树下,共用一个 我们先在文档加个提示。 |
Taro v3.4 修复 |
- Teleport - https://vuejs.org/guide/built-ins/teleport.html - NervJS/taro#11751 (comment) - 节点 id 问题 - https://docs.taro.zone/docs/ref - NervJS/taro@2db9bdf#diff-d7ae218b39f54c0aed1ec3bd9d0a3e57347bf7df7583e0e354ba6d9630433acaR36-R43 - NervJS/taro#7317 (comment) - https://github.com/NervJS/taro/blob/v3.6.25/packages/taro-runtime/src/dom/node.ts#L23 - 获取页面根节点 - https://github.com/NervJS/taro/blob/v3.6.25/packages/taro-plugin-vue3/src/runtime/connect.ts#L88 - https://github.com/NervJS/taro/blob/v3.6.25/packages/taro-runtime/src/next-tick.ts#L21 - JSX - https://docs.taro.zone/docs/vue3#jsx - https://vuejs.org/api/general.html#function-signature - https://vuejs.org/guide/extras/render-function.html#typing-functional-components - CSS.escape - https://github.com/mathiasbynens/CSS.escape - bootstrap-vue/bootstrap-vue#5561 - facebook/react#28404 (comment)
相关平台
微信小程序
复现仓库
https://github.com/li-z/taro-bug
小程序基础库: 2.12.0
使用框架: React
复现步骤
运行项目后点击跳转到详情页,然后返回首页。然后触发子组件的 onClick 事件时,回调函数却还是详情页的函数。去掉id属性后正常。
期望结果
有无id属性都应正常
实际结果
有id属性异常
环境信息
The text was updated successfully, but these errors were encountered: