简体   繁体   English

lit-element 和 lit-html 有什么区别?

[英]What is the difference between lit-element & lit-html?

I have been learning Polymer and this came in - The future of web ( lit-element & lit-html )我一直在学习 Polymer 这进来了 - web 的未来( lit-element & lit-html

I understood that lit-html is for HTML templating with a couple of efficient techniques.我知道lit-html用于 HTML 模板,使用了几种有效的技术。 At the same time lit-element is a lightweight web component base class which has the lit-html inside it.同时lit-element是一个轻量级的 web 组件基础 class 内部有lit-html

Question: If lit-element comes with lit-html , I would solely use the lit-element for all my purposes.问题:如果lit-element带有lit-html ,我将仅将lit-element用于我的所有目的。 What exactly does lit-html doing explicitly with its own separate context. lit-html究竟用自己的独立上下文明确地做了什么。

One should choose lit-element or lit-html while developing a standalone web application?在开发独立的 web 应用程序时应该选择lit-element还是lit-html

Any help on guiding through this would be of much help!任何有关指导的帮助都会有很大帮助!

First, lets clarify the following points:首先,让我们澄清以下几点:

  • Web Components technologies are supported in modern browsers by default. Web 现代浏览器默认支持组件技术。 You can build a Web Component application using the browser's API.您可以使用浏览器的 API 构建 Web 组件应用程序。

  • HTML templates has been around since 2013 at least. HTML 模板至少从 2013 年就已经存在。

lit-element library is a "lightweight" version of Web Components. lit-element库是 Web 组件的“轻量级”版本。 You'd use it if you want to build an application in Web Component and if you do so, you'd be using its built-in lit-html via html to create HTML templates如果您想在 Web 组件中构建应用程序,则可以使用它,如果这样做,您将通过html使用其内置的lit-html来创建Z4C4AD5FCA2E7A3AAF74DBB1CED00381 模板

On the other hand, Just like you stated, lit-html is a library which has efficient mechanism to create and update HTML templates.另一方面,正如您所说, lit-html是一个库,它具有创建和更新 HTML 模板的有效机制。 You can use it for whenever you'd need an HTML template irrespective of the framework/library you are using for your website, if any.无论您为网站使用的框架/库(如果有)如何,您都可以在需要 HTML 模板的任何时候使用它。

For an example, you could build a website with jQuery or vanilla Web Components and use lit-html to create the HTML templates.例如,您可以使用jQuery或 vanilla Web 组件构建网站,并使用lit-html创建 HTML 模板。

lit-html is a library which deals with dom rendering like other libraries eg React It uses the newest way of diffing the dom tree with help of native tagged templates. lit-html 是一个像其他库一样处理 dom 渲染的库,例如 React 它使用最新的方法来区分 dom 树,并借助本机标记模板。

var h1 = html`<h1>Header 1 <h1>`

like any other framework/library eg JSX it also provides you construct inside the tagged template and directives to help.像任何其他框架/库(例如 JSX)一样,它还为您提供了在标记模板和指令内的构造以提供帮助。

LitElement is a lightweight framework using lit-html as rendering engine. LitElement 是一个使用 lit-html 作为渲染引擎的轻量级框架。 It provides you the observed properties, attributes and web components lifecycle callbacks它为您提供观察到的属性、属性和 web 组件生命周期回调

For a web application you should go with LitElement, if you do not want to reinvent the data binding, caching, callbacks etc. you would definitely require more like state tracking, routing etc. which you can employ from other libraries or develop your own.对于 web 应用程序,您应该使用 LitElement go,如果您不想重新发明数据绑定、缓存、回调等。您肯定需要更多类似 Z9ED39E2EA931586B6A985A6942EF573E 的应用程序或开发您自己的跟踪等库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM