Static HTML

Interprets a template literal as an HTML template that can efficiently render to and update a container.

导入

import { html } from 'lit/static-html.js';

签名

html(strings, values): TemplateResult<ResultType>

参数

strings
TemplateStringsArray
values
Array<unknown>

详情

Includes static value support from lit-html/static.js.

Tags a string literal so that it behaves like part of the static template strings instead of a dynamic value.

导入

import { literal } from 'lit/static-html.js';

签名

literal(strings, values): StaticValue

参数

strings
TemplateStringsArray
values
Array<unknown>

详情

The only values that may be used in template expressions are other tagged literal results or unsafeStatic values (note that untrusted content should never be passed to unsafeStatic). Users must take care to ensure that adding the static string to the template results in well-formed HTML, or else templates may break unexpectedly. Static values can be changed, but they will cause a complete re-render since they effectively create a new template.

Interprets a template literal as an SVG template that can efficiently render to and update a container.

导入

import { svg } from 'lit/static-html.js';

签名

svg(strings, values): TemplateResult<ResultType>

参数

strings
TemplateStringsArray
values
Array<unknown>

详情

Includes static value support from lit-html/static.js.

Wraps a string so that it behaves like part of the static template strings instead of a dynamic value.

导入

import { unsafeStatic } from 'lit/static-html.js';

签名

unsafeStatic(value): StaticValue

参数

value
string

详情

Users must take care to ensure that adding the static string to the template results in well-formed HTML, or else templates may break unexpectedly. Note that this function is unsafe to use on untrusted content, as it will be directly parsed into HTML. Do not pass user input to this function without sanitizing it. Static values can be changed, but they will cause a complete re-render since they effectively create a new template.

Wraps a lit-html template tag (html or svg) to add static value support.

导入

import { withStatic } from 'lit/static-html.js';

签名

withStatic(coreTag): (strings: TemplateStringsArray, values: Array<unknown>) => TemplateResult<ResultType>

参数

coreTag
(strings: TemplateStringsArray, values: Array<unknown>) => TemplateResult<1> | (strings: TemplateStringsArray, values: Array<unknown>) => TemplateResult<2>

导入

import { StaticValue } from 'lit/static-html.js';

方法和属性

A value that can't be decoded from ordinary JSON, make it harder for a attacker-controlled data that goes through JSON.parse to produce a valid StaticValue.