lit-element

一个用于创建快速、轻量级 web 组件的简单基类。(A simple base class for creating fast, lightweight web components)

  • Owner: lit/lit-element
  • Platform: Cross-platform, Web browsers
  • License:: BSD 3-Clause "New" or "Revised" License
  • Category::
  • Topic:
  • Like:
    5
      Compare:

Github stars Tracking Chart

LitElement

一个简单的基类,用于使用 lit-html 创建快速,轻量级的 Web 组件。

文献资料

完整文档可在 lit-element.polymer-project.org 中找到。

总览

LitElement 使用 lit-html 渲染到元素的 Shadow DOM 中,并添加了 API 以帮助管理元素的属性和属性。 LitElement 对属性更改做出反应,并使用 lit-html 进行声明式渲染。 有关如何为 lit-element 创建模板的其他信息,请参见 lit-html 指南

import {LitElement, html, css, customElement, property} from 'lit-element';
    // This decorator defines the element.
    @customElement('my-element')
    export class MyElement extends LitElement {
      // This decorator creates a property accessor that triggers rendering and
      // an observed attribute.
      @property()
      mood = 'great';
      static styles = css`
        span {
          color: green;
        }`;
      // Render element DOM by returning a `lit-html` template.
      render() {
        return html`Web Components are <span>${this.mood}</span>!`;
      }
    }
    <my-element mood="awesome"></my-element>

注意,此示例使用装饰器创建属性。 装饰器是当前在 TypeScript 或 Babel 中可用的提议标准。 LitElement 还支持声明反应特性的 vanilla JavaScript 方法

示例

安装

从项目文件夹中运行

$ npm install lit-element

安装旧浏览器所需的 web 组件 polyfills

$ npm i -D @webcomponents/webcomponentsjs

受支持的浏览器

支持所有现代浏览器的最后两个版本,包括Chrome、Safari、Opera、Firefox和Edge。此外,还支持Internet Explorer 11。

Edge和Internet Explorer 11需要 web 组件 polyfills。

贡献

请查看 CONTRIBUTING.md

Main metrics

Overview
Name With Ownerlit/lit-element
Primary LanguageTypeScript
Program languageTypeScript (Language Count: 3)
PlatformCross-platform, Web browsers
License:BSD 3-Clause "New" or "Revised" License
所有者活动
Created At2017-09-02 19:09:16
Pushed At2025-06-03 06:19:42
Last Commit At2022-02-03 12:09:17
Release Count27
Last Release Namev2.4.0 (Posted on )
First Release Namev0.3.0 (Posted on 2018-04-19 13:03:05)
用户参与
Stargazers Count4.5k
Watchers Count143
Fork Count318
Commits Count1k
Has Issues Enabled
Issues Count713
Issue Open Count0
Pull Requests Count344
Pull Requests Open Count47
Pull Requests Close Count133
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

LitElement

A simple base class for creating fast, lightweight web components with lit-html.

Build Status
Published on npm
Join our Slack
Published on webcomponents.org
Mentioned in Awesome lit-html
BrowserStack Status

Documentation

Full documentation is available at lit-element.polymer-project.org.

Overview

LitElement uses lit-html to render into the
element's Shadow DOM
and adds API to help manage element properties and attributes. LitElement reacts to changes in properties
and renders declaratively using lit-html. See the lit-html guide
for additional information on how to create templates for lit-element.

    import {LitElement, html, css, customElement, property} from 'lit-element';

    // This decorator defines the element.
    @customElement('my-element')
    export class MyElement extends LitElement {

      // This decorator creates a property accessor that triggers rendering and
      // an observed attribute.
      @property()
      mood = 'great';

      static styles = css`
        span {
          color: green;
        }`;

      // Render element DOM by returning a `lit-html` template.
      render() {
        return html`Web Components are <span>${this.mood}</span>!`;
      }

    }
    <my-element mood="awesome"></my-element>

Note, this example uses decorators to create properties. Decorators are a proposed
standard currently available in TypeScript or Babel. LitElement also supports a vanilla JavaScript method of declaring reactive properties.

Examples

Installation

From inside your project folder, run:

$ npm install lit-element

To install the web components polyfills needed for older browsers:

$ npm i -D @webcomponents/webcomponentsjs

Supported Browsers

The last 2 versions of all modern browsers are supported, including
Chrome, Safari, Opera, Firefox, Edge. In addition, Internet Explorer 11 is also supported.

Edge and Internet Explorer 11 require the web components polyfills.

Contributing

Please see CONTRIBUTING.md.