欧美free性护士vide0shd,老熟女,一区二区三区,久久久久夜夜夜精品国产,久久久久久综合网天天,欧美成人护士h版

首頁綜合 正文
目錄

柚子快報激活碼778899分享:Google的新前端框架Lit

柚子快報激活碼778899分享:Google的新前端框架Lit

http://yzkb.51969.com/

Google的新框架 Lit ,有 Google 加持的框架引起了我的興趣,就去簡單的了解了一下,簡單的給大家分享一下學(xué)習(xí)成果。由于Lit框架還在快遞迭代中,文中講到的一些代碼實現(xiàn)很可能已經(jīng)重構(gòu),感興趣的同學(xué),可以去翻一下Lit源碼。

什么是 Lit

Lit 是一個基于 Web-Component 構(gòu)建的前端框架,前身基本可以理解為即 Polymer , Lit 提供了如下具有競爭力的特性

基于 Web-Component 的更高層封裝,提供了現(xiàn)代前端開發(fā)習(xí)慣的響應(yīng)式數(shù)據(jù),聲明式的模版,減少了web component的一部分樣板代碼. 小。運行時僅有5K 性能強悍。規(guī)避了 VDOM 的一些弊端,更新時僅處理 UI 中的異步部分(可以理解成僅處理響應(yīng)式的部分) 兼容性較好。因為 web-component 是 HTML 的原生能力,也就代表著 web-component 可以在任何使用 HTML 的地方使用,框架無關(guān)。

小和框架無關(guān)是促使我關(guān)注這個框架的一個重點(svelte也是,有時間再說,學(xué)不動了),因為對于一些通用業(yè)務(wù)代碼來說, 運行時盡可能的小 和 框架無關(guān) 是最核心的兩個技術(shù)選型指標(biāo)。

什么是 Web-Component

Web Components is a suite of different technologies allowing you to create reusable custom elements — with their functionality encapsulated away from the rest of your code — and utilize them in your web apps.

我個人認為,組件化是現(xiàn)在前端快速發(fā)展和規(guī)模壯大的一個比較重要的原因,想想寫 JQ 的年代,HTML 代碼基本都長這個樣子

html

代碼解讀

復(fù)制代碼

按鈕
按鈕
按鈕

哪怕后面出現(xiàn)了模版語法,狀況也沒有變得更好(與服務(wù)端協(xié)作共用模版 -> JSP or 要在JS中封裝方法,通過模版語法注入 -> handlebars),單純的loop循環(huán)渲染可能能方便的解決DOM復(fù)用的問題,但是跨層級的組件復(fù)用仍然是一個問題。

因此任何一個想要進一步發(fā)展的前端框架技術(shù),組件化是必不可少的一步。 Web-Component 就是這樣一個瀏覽器原生支持的創(chuàng)建可重用元素(自定義組件)的能力,而 Lit 則是基于 Web-Component 構(gòu)建的。

那我們需要先了解下 Web-Component

Web-Component 的簡單開發(fā)流

Create a class in which you specify your web component functionality, using the ECMAScript 2015 class syntax Register your new custom element using the CustomElementRegistry.define() method, passing it the element name to be defined, the class or function in which its functionality is specified, and optionally, what element it inherits from. If required, attach a shadow DOM to the custom element using Element.attachShadow() method. Add child elements, event listeners, etc., to the shadow DOM using regular DOM methods. If required, define an HTML template using