element-plus [Component] [image] Cannot trigger click when image error occurs

nhaq1z21  于 2个月前  发布在  其他
关注(0)|答案(5)|浏览(43)

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

  • el-image

Element Plus Playground

Steps to reproduce

如题

What is Expected?

error时,也应该触发click事件

What is actually happening?

没有触发,仅正常返回的图片可触发click

console并没有打印输出

Additional comments

需求:当验证码图片报错时,点击会再次请求新的验证码。

qcuzuvrc

qcuzuvrc1#

Can you directly use the errer slot to achieve it

egdjgwm8

egdjgwm82#

Can you directly use the errer slot to achieve it

Of 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.

z2acfund

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 the img element inside, just register them one by one.
  • Without changing 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.

14ifxucb

14ifxucb4#

TIP

The useAttrs function has a parameter excludeListeners

wvyml7n5

wvyml7n55#

TIP

The useAttrs function has a parameter excludeListeners

Thx,i didnt know before.

相关问题