Skip to content

fix load、error event#8

Open
dengnanhao wants to merge 1 commit intoranuts:mainfrom
dengnanhao:feature/events-error
Open

fix load、error event#8
dengnanhao wants to merge 1 commit intoranuts:mainfrom
dengnanhao:feature/events-error

Conversation

@dengnanhao
Copy link
Copy Markdown

CustomElement 类使用了内部的 onLoad 和 onError 回调函数,这些回调函数仅仅移除了加载元素,但从未向 DOM 分派 load 和 error 事件。所以文档中的load和error事件并未生效

修改内容(components/preview/index.ts:194-199):

  1. onLoad 回调中增加了 this.dispatchEvent(new CustomEvent('load', { bubbles: true, composed: true }))
  2. onError 回调中增加了 this.dispatchEvent(new CustomEvent('error', { bubbles: true, composed: true }))

composed: true 确保事件能穿透 Shadow DOM 向上冒泡,可以正常监听:

document.querySelector('r-preview').addEventListener('load', (e) => { ... });
document.querySelector('r-preview').addEventListener('error', (e) => { ... });

@dengnanhao
Copy link
Copy Markdown
Author

修复issues/7

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

Successfully merging this pull request may close these issues.

1 participant