作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 LitElement 创建一个 Web 组件。这是来自 https://lit-element.polymer-project.org/guide/start
// Import the LitElement base class and html helper function
import { LitElement, html } from 'lit-element';
// Extend the LitElement base class
class MyElement extends LitElement {
/**
* Implement `render` to define a template for your element.
*
* You must provide an implementation of `render` for any element
* that uses LitElement as a base class.
*/
render(){
/**
* `render` must return a lit-html `TemplateResult`.
*
* To create a `TemplateResult`, tag a JavaScript template literal
* with the `html` helper function:
*/
return html`
<!-- template content -->
<p>A paragraph</p>
`;
}
}
// Register the new element with the browser.
customElements.define('my-element', MyElement);
最佳答案
只是为了确保这个问题显示为已回答:createRenderRoot
允许您覆盖创建影子根的操作。它通常用于渲染到 light dom:
createRenderRoot() {
return this;
}
虽然它可以用来完全渲染其他地方。
关于javascript - 如何在没有 Shadow DOM 的情况下创建 LitElement?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55126694/
我是一名优秀的程序员,十分优秀!