我应该手动将自定义剔除元素注册到 DOM 吗?
Should I manually register custom knockout elements to the DOM?
在淘汰赛中,我们可以创建看起来像这样的 custom elements:
<flight-deals params='from: "lhr", to: "sfo"'></flight-deals>
自定义元素在HTML中的定义仍然是work in progress and a part of the process of using this today是使用document.registerElement
将自定义元素注册到DOM。
但是,我在敲除文档中找不到关于这些方面的任何内容,当我调查我的 custom elements are registered 调用 ko.components.register
后是否通过敲除 DOM 时,他们转向出不了。
所以如果我在 knockout 中使用自定义元素,我是否也应该确保使用 document.registerElement
手动注册这些元素?淘汰赛还没有做到这一点让我有点困惑。
您不需要为现代浏览器和 IE9+ 做任何特别的事情。
对于 IE6 - IE8 支持,您确实需要意识到这一点并使用一点魔法。正如 the relevant documentation 提到的:
- HTML5-era browsers, which includes Internet Explorer 9 and later, automatically allow for custom elements with no difficulties.
- Internet Explorer 6 to 8 also supports custom elements, but only if they are registered before the HTML parser encounters any of those elements.
IE 6-8’s HTML parser will discard any unrecognized elements. To ensure it doesn’t throw out your custom elements, you must do one of the following:
- Ensure you call
ko.components.register('your-component')
before the HTML parser sees any <your-component>
elements
- Or, at least call
document.createElement('your-component')
before the HTML parser sees any <your-component>
elements. You can ignore the result of the createElement call — all that matters is that you have called it.
在淘汰赛中,我们可以创建看起来像这样的 custom elements:
<flight-deals params='from: "lhr", to: "sfo"'></flight-deals>
自定义元素在HTML中的定义仍然是work in progress and a part of the process of using this today是使用document.registerElement
将自定义元素注册到DOM。
但是,我在敲除文档中找不到关于这些方面的任何内容,当我调查我的 custom elements are registered 调用 ko.components.register
后是否通过敲除 DOM 时,他们转向出不了。
所以如果我在 knockout 中使用自定义元素,我是否也应该确保使用 document.registerElement
手动注册这些元素?淘汰赛还没有做到这一点让我有点困惑。
您不需要为现代浏览器和 IE9+ 做任何特别的事情。
对于 IE6 - IE8 支持,您确实需要意识到这一点并使用一点魔法。正如 the relevant documentation 提到的:
- HTML5-era browsers, which includes Internet Explorer 9 and later, automatically allow for custom elements with no difficulties.
- Internet Explorer 6 to 8 also supports custom elements, but only if they are registered before the HTML parser encounters any of those elements.
IE 6-8’s HTML parser will discard any unrecognized elements. To ensure it doesn’t throw out your custom elements, you must do one of the following:
- Ensure you call
ko.components.register('your-component')
before the HTML parser sees any<your-component>
elements- Or, at least call
document.createElement('your-component')
before the HTML parser sees any<your-component>
elements. You can ignore the result of the createElement call — all that matters is that you have called it.