lit-element - lit-element styles within html template versus static styles getter?
问题描述
given the following code, and the lit-html vscode extension, syntax highlighting doesn't work on the static styles getter
class MyComponent extends LitElement {
// SYNTAX HIGHLIGHTING FAILS
static get styles() {
return css`
* {}
`
}
// SYNTAX HIGHLIGHTING WORKS
render() {
return html`
<style>
* {}
</style>
`
}
}
however it does work in the html template in the render function
how bad, for performance, is opting for the styles in the render function, instead of the static styles getter?
解决方案
将样式移动到渲染函数中意味着:
- 失去所有的性能提升(你通过使用可构造的样式表获得)
- 并且它可能会诱使您在其中使用
${this.foo}
(如果您想要高性能或想要支持非本机 shadow dom 浏览器,这是一个坏主意)
所以我会说为语法突出显示这样做是个坏主意。
您可以通过使用更多/不同的插件来获得它们:
- lit-plugin lit-html 的语法高亮、类型检查和代码完成(替换 lit-html vscode 扩展)
- vscode-styled-components突出显示所有 css 标记的模板文字(单独添加 css 突出显示 - 例如将其与 lit-html vscode 扩展结合起来)
您应该始终在此处找到最新列表https://open-wc.org/developing/ide.html#plugins
推荐阅读
- javascript - 如何使背景图像的某些部分可点击
- keras - Keras中model.evaluate()的最佳batch_size?
- python - 对熊猫数据框中的不同值求和
- shell - 如何在有限的时间内等待用户响应,否则继续使用 shell 中的脚本
- javascript - 如何修剪javascript数组
- python - pyodbc 不返回 SQL 结果并且不抛出错误
- xslt - 使用 xslt 在同一 xpath 中将段添加到 xml
- amazon-web-services - Docker 编写 AWS
- vb.net - VB.NET ComboBox 无法识别文本更改
- python - 打印使用 lxml 抓取和解析的表数据