javascript - 如何在 polymer3 的模板中嵌入 html 代码(如 unsafeHTML)
问题描述
static get template() {
return html`
<p>This content is from ChildClass.</p>
<p>${super.template}</p>
<p>Hello again from ChildClass.</p>
<p style='color:red'>[[partHtml]] <==== this should be 'hello'</p>
`;
}
get partHtml()
{
return "<span>hello</span>";
}
我想像partHtml
普通 HTML 一样被注入到模板中。
我知道 lit-element 中的不安全 HTML 可以做到这一点,但是 lit-element 不能使用super.render()
东西,它不像聚合物元素那样方便。
解决方案
如何使用inner-h-t-m-l
属性
static get template() {
return html`
<p>This content is from ChildClass.</p>
<p>${super.template}</p>
<p>Hello again from ChildClass.</p>
<p style='color:red' inner-h-t-m-l="[[partHtml]]"></p>
`;
}
get partHtml()
{
return "<span>hello</span>";
}
推荐阅读
- angular - 如何使用 ToastrService 在 Angular 中显示服务器错误的 Toastr 通知
- python - 如何让机器人响应特定反应?不和谐.py
- jenkins - 如何在 jenkins 管道中使用 emailext-template 来获取模板?
- azure-devops - Azure Devops / Loop 并在单个 bash 脚本中显示所有模板参数
- r - 当这些行值出现在 R 中的 df2 中时,返回 df1 的行索引
- excel - 数据透视表度量不一致
- python - 在 Python 中查找缺少 .csv 文件的目录
- python - 无法解决“不允许的方法 - 请求的 URL 不允许该方法。” 错误
- c# - 单线程枚举有效,但多线程无效,不知道为什么
- android - 为什么要在安卓手机上发布Apk显示灰屏?