-
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
子组件处理点击事件时如果将自身设置为null导致不可见时, 会触发事件冒泡 (已设置e.stopPropagation()) #8757
Comments
可以先用 useCallback 包裹回调函数来绕过。 |
升级到taro3.1.1, 实测并未修复? @Chen-jj |
@yangxudong-functorz 还有问题么?把 lock 文件删除重新安装一下依赖? |
3.1.2无法阻止冒泡 |
@yaobiao131 提供一下代码 |
const TestTab = () => { const [loading, setLoading] = useState(false) 点击修改加载状态的话就无法阻止冒泡 |
3.0.22版本就没有这个问题 |
@yaobiao131 复现不了,Taro v3.1.2 import { Component, useEffect, useRef, useState } from 'react'
import { View, Text, Button } from '@tarojs/components'
import Taro from '@tarojs/taro'
import './index.scss'
const TestTab = () => {
const [loading, setLoading] = useState(false)
return (
<View onClick={async (e) => {
console.log('parent')
}}
>
<Button
loading={loading}
size='small'
onClick={(e) => {
e.stopPropagation()
setLoading(true)
console.log('children')
}}
>
点我
</Button>
</View>
)
}
export default class Index extends Component {
render () {
return (
<View className='index'>
<TestTab></TestTab>
</View>
)
}
} |
import React, { useState } from 'react'
import { Button, ScrollView, View } from '@tarojs/components'
const TestTab = () => {
const [loading, setLoading] = useState(false)
return (
<View onClick={async (e) => {
console.log('parent')
}}
>
<View>
<Button
loading={loading}
size='small'
onClick={(e) => {
e.stopPropagation()
setLoading(true)
console.log('children')
}}
>点我</Button>
</View>
</View>
)
}
export default TestTab 嵌套view的情况下无法阻止 |
该问题依然存在 ~ 版本 3.2.12 @Chen-jj |
该问题依然存在 ~ 版本 3.3.16 @Chen-jj |
相关平台
微信小程序
复现仓库
https://github.com/yangxudong-functorz/taro_issues/blob/main/issue0.ts
小程序基础库: 2.13.0
使用框架: React
复现步骤
点击红色view, 会触发红色view的onClick事件, 红色view会消失, 同时会触发绿色父组件的onClick事件, 此时console里会出现两条log.
期望结果
红色view消失, console中只显示一条 'i am child' log
实际结果
红色view消失, console中显示i am child' 和 'i am parent'
环境信息
补充信息
使用如下代码可防止此问题产生:
setTimeout(() => {
setShowChild(false);
}, 0);
The text was updated successfully, but these errors were encountered: