我是 Lit-Element 的新手,在作为属性字符串传递时无法输出原始 HTML。我猜有更好的方法来实现这一点,任何帮助将不胜感激。
JS Fiddle 在这里显示我的问题: https : //jsfiddle.net/32dnvkwq/
<script src="https://unpkg.com/@webcomponents/webcomponentsjs@next/webcomponents-loader.js"></script>
<script type="module">
import {LitElement, html} from 'https://unpkg.com/@polymer/lit-element@latest/lit-element.js?module';
class MyElement extends LitElement {
static get properties() {
return { str: String }
}
render() {
return html `${this.str}`;
}
}
customElements.define('my-element', MyElement);
</script>
<my-element str="line1<br />line2"></my-element>
Run Code Online (Sandbox Code Playgroud)
输出:
line1<br />line2