你正在查看 Lit 的旧版本文档。点击 这里查看最新版本。

Templates

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

导入

import { html } from 'lit-html';

签名

html(strings, values): TemplateResult

参数

strings
TemplateStringsArray
values
Array<unknown>

A sentinel value that signals a NodePart to fully clear its content.

导入

import { nothing } from 'lit-html';

类型

symbol

Renders a template result or other value to a container.

导入

import { render } from 'lit-html';

签名

render(result, container, options?): void

参数

result
unknown

Any value renderable by NodePart - typically a TemplateResult created by evaluating a template tag like html or svg.

container
MDN Element | MDN DocumentFragment

A DOM parent to render to. The entire contents are either replaced, or efficiently updated if the same result type was previous rendered there.

options?
Partial<RenderOptions>

RenderOptions for the entire render tree rendered to this container. Render options must not change between renders to the same container, as those changes will not effect previously rendered DOM.

详情

To update a container with new values, reevaluate the template literal and call render with the new result.

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

导入

import { svg } from 'lit-html';

签名

svg(strings, values): SVGTemplateResult

参数

strings
TemplateStringsArray
values
Array<unknown>

A TemplateResult for SVG fragments.

导入

import { SVGTemplateResult } from 'lit-html';

详情

This class wraps HTML in an <svg> tag in order to parse its contents in the SVG namespace, then modifies the template to remove the <svg> tag so that clones only container the original fragment.

方法和属性

new SVGTemplateResult(strings, values, type, processor): SVGTemplateResult

永久链接到 constructor
参数
strings
TemplateStringsArray
values
ReadonlyArray<unknown>
type
string
processor
TemplateProcessor

readonly strings: TemplateStringsArray

永久链接到 strings 查看源码

readonly values: ReadonlyArray<unknown>

永久链接到 values 查看源码

Returns a string of HTML used to create a <template> element.

The return type of html, which holds a Template and the values from interpolated expressions.

导入

import { TemplateResult } from 'lit-html';

方法和属性

new TemplateResult(strings, values, type, processor): TemplateResult

永久链接到 constructor 查看源码
参数
strings
TemplateStringsArray
values
ReadonlyArray<unknown>
type
string
processor
TemplateProcessor

readonly strings: TemplateStringsArray

永久链接到 strings 查看源码

readonly values: ReadonlyArray<unknown>

永久链接到 values 查看源码

Returns a string of HTML used to create a <template> element.

导入

import { RenderOptions } from 'lit-html';

方法和属性

readonly eventContext?: EventTarget

永久链接到 eventContext 查看源码

readonly templateFactory: TemplateFactory

永久链接到 templateFactory 查看源码