Bug Type: Component
Environment
- Vue Version:
3.5.0-alpha.2
- Element Plus Version:
2.7.7
- Browser / OS:
chrome 126.0.6478.127
- Build Tool:
Vite
Reproduction
Related Component
el-image
Reproduction Link
Element Plus Playground
Steps to reproduce
如题
What is Expected?
error时,也应该触发click事件
What is actually happening?
没有触发,仅正常返回的图片可触发click
console并没有打印输出
Additional comments
需求:当验证码图片报错时,点击会再次请求新的验证码。
5条答案
按热度按时间qcuzuvrc1#
Can you directly use the
errer slot
to achieve itegdjgwm82#
Can you directly use the
errer slot
to achieve itOf course, it's simple.But the point should be that it should respond to click regardless of whether it is loaded incorrectly, rather than ignoring it in another way.This problem still exists.
z2acfund3#
After reading the source code, I found that the image component sets the attribute inheritance inheritAttrs to false, and explicitly uses useAttrs to bind the variable to the img element instead of the outer div. This will cause the outer layer to fail to get the click, contextmenu and other events normally. Only when the inner img element is loaded correctly can the event bubble mechanism be used to capture the event correctly. I don't think useAttrs should be bound to the img element directly, so that although some properties passed to the image can be directly obtained, some events passed externally cannot be triggered when the image is loaded (placeholder slot) or when the image fails to load (error slot).
In addition, I believe that the solution to this problem should not be to add click to the el-image and then register the same click on the error slot.
solution
inheritAttrs: true
, but there are only a few attributes of theimg
element inside, just register them one by one.inheritAttrs
, the code maintains event-related property objects separately,v-bind="containerAttrs"
is bound to the external container, and'img' unbinds these events to avoid multiple triggers.@tolking, what do you think? If you agree, I will submit pr to solve it, thanks.
14ifxucb4#
TIP
The
useAttrs
function has a parameterexcludeListeners
wvyml7n55#
TIP
The
useAttrs
function has a parameterexcludeListeners
Thx,i didnt know before.