使用Shadow DOM有什么缺点? [英] What are the drawbacks of using Shadow DOM?

查看:268
本文介绍了使用Shadow DOM有什么缺点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在教程中我只看到了Shadow DOM的好处,但也应该有缺点。在哪些情况下我们应该避免使用Shadow DOM?

In the tutorials I see only the benefits of Shadow DOM, but there should be drawbacks as well. In which cases should we avoid using Shadow DOM?

推荐答案

Shadow DOM功能可以被视为缺点和好处:

Shadow DOM features can be seen as drawback as much as benefits:

样式隔离是一个好处,但如果用户想要使用全局CSS样式表中的Shadow DOM设置样式,那么这是一个缺点。

Style isolation is a benefit if you want it but a drawback if a user wants to style a component with Shadow DOM from a global CSS stylesheet.

DOM Shadowing 在某些情况下是一个好处,但如果外部脚本/库或扩展需要解析或选择内容,这是一个缺点。

DOM Shadowing is a benefit in some cases, but a drawback if an external script/library or extension needs to parse or select the content.

有许多第三方库(或扩展)不能与Shadow DOM内容一起使用,因为它们不是为处理它而设计的,或者需要一些额外的配置才能使用Shadow DOM。

There are many 3rd party libraries (or extensions) that won't work with Shadow DOM content because they were not designed to deal with it, or need some additional configuration to work with Shadow DOM.

示例:

  • Disqus comments integration
  • CodeMirror editor integration
  • Wiris math editor integration

此外,解析HTML的扩展将在Shadow DOM边界被阻止:a如果你不想发现它就会受益,如果你认为它们是一种有用的服务,这是一个缺点。

Also, extensions that parse HTML will be blocked at the Shadow DOM boundary: a benefit if you don't want to spied, a drawback if you consider them as a useful service.

事件传播在内外都是不同的暗影DOM。所以你可能有一些扩散来处理UI事件。

Event propagation is different inside and outside the Shadow DOM. So you may have some diffuclties to deal with UI events.

示例:

  • TinyMCE integration

结论


  • 仅在需要CSS样式或DOM隔离时才使用Shadow DOM。

  • Use Shadow DOM only if you want CSS style or DOM isolation.

如果您需要与某些不合规的第三方组件或库进行交互,请不要使用Shadow DOM。

Don't use Shadow DOM if you need to interact with some not compliant third party components or library.

这篇关于使用Shadow DOM有什么缺点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆