QuickUI:輕量級前端框架
GitHub
(原名PDQuickUI,從0.6.0版本開始更名為QuickUI)
QuickUI是一個源自PDRenderKit的前端渲染框架,專注於增強前端框架功能。
透過整合虛擬DOM,重寫渲染邏輯,提高渲染效率,實現更快的資料觀察和自動更新。
該專案從 PDRenderKit 中刪除了原型擴展,以確保相容性和效能,使其適合複雜的應用程式。
它提供模組和非模組版本,並將 PDRenderKit 中的授權從 GPL-3.0 更改為 MIT。
特徵
- 清晰的架構:將UI與資料邏輯分離,使其更易於維護。
- 程式碼簡潔:減少冗餘程式碼,增強可讀性。
- 自動渲染:自動監控資料變化與更新,盡量減少手動操作。
- 輕量級:在小於 20kb 的檔案大小內保持完整功能。
安裝
-
從 npm 安裝
npm i @pardnchiu/quickui
登入後複製登入後複製登入後複製 -
包含來自 CDN
-
直接包含QuickUI
<!-- Version 0.6.0 and above --> <script src="https://cdn.jsdelivr.net/npm/@pardnchiu/quickui@[VERSION]/dist/QuickUI.js"></script> <!-- Version 0.5.4 and below --> <script src="https://cdn.jsdelivr.net/npm/pdquickui@[VERSION]/dist/PDQuickUI.js"></script>
登入後複製登入後複製 -
模組版本
// Version 0.6.0 and above import { QUI } from "https://cdn.jsdelivr.net/npm/@pardnchiu/quickui@[VERSION]/dist/QuickUI.esm.js"; // Version 0.5.4 and below import { QUI } from "https://cdn.jsdelivr.net/npm/pdquickui@[VERSION]/dist/PDQuickUI.module.js";
登入後複製登入後複製
-
用法
-
初始化 QUI
const app = new QUI({ id: "", // Specify rendering element data: { // Custom DATA }, event: { // Custom EVENT }, when: { before_render: function () { // Stop rendering }, rendered: function () { // Rendered }, before_update: function () { // Stop updating }, updated: function () { // Updated }, before_destroy: function () { // Stop destruction }, destroyed: function () { // Destroyed } } });
登入後複製登入後複製
概述
自動渲染:偵測到資料變更時自動重新載入。
屬性概述
Attribute | Description |
---|---|
{{value}} | Inserts text into HTML tags and automatically updates with data changes. |
:path | Used with the temp tag to load HTML fragments from external files into the current page. |
:html | Replaces the element's innerHTML with text. |
:for | Supports formats like item in items, (item, index) in items, (key, value) in object. Iterates over data collections to generate corresponding HTML elements. |
:if :else-if :elif :else |
Displays or hides elements based on specified conditions, enabling branching logic. |
:model | Binds data to form elements (e.g., input), updating data automatically when input changes. |
:hide | Hides elements based on specific conditions. |
:animation | Specifies transition effects for elements, such as fade-in or expand, to enhance user experience. |
:mask | Controls block loading animations, supporting `true |
:[attr] | Sets element attributes, such as ID, class, image source, etc. Examples: :id/:class/:src/:alt/:href... |
:[css] | Sets element CSS, such as margin, padding, etc. Examples: :background-color, :opacity, :margin, :top, :position... |
@[event] | Adds event listeners that trigger specified actions upon activation. Examples: @click/@input/@mousedown... |
文字替換
{{價值}}
-
index.html
npm i @pardnchiu/quickui
登入後複製登入後複製登入後複製 -
結果
<!-- Version 0.6.0 and above --> <script src="https://cdn.jsdelivr.net/npm/@pardnchiu/quickui@[VERSION]/dist/QuickUI.js"></script> <!-- Version 0.5.4 and below --> <script src="https://cdn.jsdelivr.net/npm/pdquickui@[VERSION]/dist/PDQuickUI.js"></script>
登入後複製登入後複製
:html
-
index.html
// Version 0.6.0 and above import { QUI } from "https://cdn.jsdelivr.net/npm/@pardnchiu/quickui@[VERSION]/dist/QuickUI.esm.js"; // Version 0.5.4 and below import { QUI } from "https://cdn.jsdelivr.net/npm/pdquickui@[VERSION]/dist/PDQuickUI.module.js";
登入後複製登入後複製 -
結果
const app = new QUI({ id: "", // Specify rendering element data: { // Custom DATA }, event: { // Custom EVENT }, when: { before_render: function () { // Stop rendering }, rendered: function () { // Rendered }, before_update: function () { // Stop updating }, updated: function () { // Updated }, before_destroy: function () { // Stop destruction }, destroyed: function () { // Destroyed } } });
登入後複製登入後複製
插入區塊
> [!注意]
>確保在測試時停用瀏覽器中的本機檔案限製或使用即時伺服器。
:小路
-
test.html
<h1>{{ title }}</h1> const app = new QUI({ id: "app", data: { title: "test" } });
登入後複製 -
index.html
<h1>test</h1>
登入後複製 -
結果
const app = new QUI({ id: "app", data: { html: "<b>innerHtml</b>" } });
登入後複製
循環渲染
:為了
-
index.html
<b>innerHtml</b>
登入後複製 -
結果
<h1>path heading</h1> <p>path content</p>
登入後複製 -
結果
const app = new QUI({ id: "app" });
登入後複製
條件渲染
-
index.html
<h1>path heading</h1> <p>path content</p>
登入後複製 -
結果:標題 = 1
<ul> <li>{{ item }} {{ CALC(index + 1) }}</li> </ul> const app = new QUI({ id: "app", data: { ary: ["test1", "test2", "test3"] } });
登入後複製 -
結果:heading = null && isH2 = true
<li>
登入後複製
Nest loop
-
index.html
-
<li>
{{ key }}: {{ val.name }}
-
{{ item.name }}
- {{ CALC(index1 + 1) }}. {{ item1.name }} - ${{ item1.price }}
登入後複製 -
{{ item.name }}
-
結果:標題 = 3 && isH2 = null
<ul> <li>food: Food <ul> <li>Snacks <ul> <li>1. Potato Chips - </li> <li>2. Chocolate - </li> </ul> </li> <li>Beverages <ul> <li>1. Juice - </li> <li>2. Tea - </li> </ul> </li> </ul> </li> <li>home: Home <ul> <li>Furniture <ul> <li>1. Sofa - 0</li> <li>2. Table - 0</li> </ul> </li> <li>Decorations <ul> <li>1. Picture Frame - </li> <li>2. Vase - </li> </ul> </li> </ul> </li> </ul>
登入後複製 -
結果:heading = null && isH2 = null
<h1>{{ title }} {{ heading }}</h1> <h2>{{ title }} {{ heading }}</h2> <h3>{{ title }} {{ heading }}</h3> <h4>{{ title }} {{ heading }}</h4> const app = new QUI({ id: "app", data: { heading: [Number|null], isH2: [Boolean|null], title: "test" } });
登入後複製
模板渲染
-
index.html
<h1>test 1</h1>
登入後複製 -
結果
<h2>test </h2>
登入後複製
綁定
<h3>test 3</h3>
活動
<h4>test </h4>
CSS
> [!注意]
>支援使用:[CSS屬性]進行簡單設置,直接將資料綁定到樣式屬性。
-
index.html
const test = new QUI({ id: "app", data: { hint: "hint 123", title: "test 123" }, render: () => { return ` "{{ hint }}", h1 { style: "background: red;", children: [ "{{ title }}" ] }` } })
登入後複製 -
結果:
hint 123 <h1>test 123</h1>
登入後複製
功能
長度()
-
index.html
test const app = new QUI({ id: "app", data: { password: null, }, event: { show: function(e){ alert("Password:", app.data.password); } } });
登入後複製 -
結果
test const app = new QUI({ id: "app", event: { test: function(e){ alert(e.target.innerText + " clicked"); } } });
登入後複製
計算()
-
index.html
test const app = new QUI({ id: "app", data: { width: "100px", color: "red" } });
登入後複製 -
結果
test
登入後複製
上() / 下()
-
index.html
<p>Total: {{ LENGTH(array) }}</p> const app = new QUI({ id: "app", data: { array: [1, 2, 3, 4] } });
登入後複製 -
結果
<p>Total: 4</p>
登入後複製
日期(數字,格式)
-
index.html
<p>calc: {{ CALC(num * 10) }}</p> const app = new QUI({ id: "app", data: { num: 1 } });
登入後複製 -
結果
<p>calc: 10</p>
登入後複製
延遲載入
:延遲載入
-
index.html
<p>{{ UPPER(test1) }} {{ LOWER(test2) }}</p> const app = new QUI({ id: "app", data: { test1: "upper", test2: "LOWER" } });
登入後複製 -
結果
<p>UPPER lower</p>
登入後複製
SVG 替換
-
測試.svg
<p>{{ DATE(now, YYYY-MM-DD hh:mm:ss) }}</p> const app = new QUI({ id: "app", data: { now: Math.floor(Date.now() / 1000) } });
登入後複製 -
index.html
<p>2024-08-17 03:40:47</p>
登入後複製 -
結果
<img> const app = new QUI({ id: "app", data: { image: "test.jpg" }, option: { lazyload: true // Enable image lazy loading: true|false (default: true) } });
登入後複製
i18n
> [!注意]
>如果format是對象,則直接配置多語言內容。
>如果格式是字串,則透過 fetch 動態載入語言檔案。
-
en.json
<img src="test.jpg">
登入後複製 -
index.html
登入後複製登入後複製 -
結果 i18nLang = zh
const app = new QUI({ id: "app", data: { svg: "test.svg", }, option: { svg: true // Enable SVG file transformation: true|false (default: true) } });
登入後複製 -
結果 i18nLang = en
登入後複製登入後複製
生命週期掛鉤
{ "greeting": "Hello", "username": "Username" }
資料擷取
npm i @pardnchiu/quickui
創作者
邱敬幃 Pardn Chiu
執照
此項目已取得專有許可證許可。
您只能根據最終使用者授權協議 (EULA) 中指定的條款使用、安裝和執行此軟體。
©️ 2024 邱敬幃 Pardn Chiu
以上是QuickUI:輕量級前端框架的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

JavaScript是現代Web開發的基石,它的主要功能包括事件驅動編程、動態內容生成和異步編程。 1)事件驅動編程允許網頁根據用戶操作動態變化。 2)動態內容生成使得頁面內容可以根據條件調整。 3)異步編程確保用戶界面不被阻塞。 JavaScript廣泛應用於網頁交互、單頁面應用和服務器端開發,極大地提升了用戶體驗和跨平台開發的靈活性。

JavaScript的最新趨勢包括TypeScript的崛起、現代框架和庫的流行以及WebAssembly的應用。未來前景涵蓋更強大的類型系統、服務器端JavaScript的發展、人工智能和機器學習的擴展以及物聯網和邊緣計算的潛力。

不同JavaScript引擎在解析和執行JavaScript代碼時,效果會有所不同,因為每個引擎的實現原理和優化策略各有差異。 1.詞法分析:將源碼轉換為詞法單元。 2.語法分析:生成抽象語法樹。 3.優化和編譯:通過JIT編譯器生成機器碼。 4.執行:運行機器碼。 V8引擎通過即時編譯和隱藏類優化,SpiderMonkey使用類型推斷系統,導致在相同代碼上的性能表現不同。

JavaScript是現代Web開發的核心語言,因其多樣性和靈活性而廣泛應用。 1)前端開發:通過DOM操作和現代框架(如React、Vue.js、Angular)構建動態網頁和單頁面應用。 2)服務器端開發:Node.js利用非阻塞I/O模型處理高並發和實時應用。 3)移動和桌面應用開發:通過ReactNative和Electron實現跨平台開發,提高開發效率。

Python更適合初學者,學習曲線平緩,語法簡潔;JavaScript適合前端開發,學習曲線較陡,語法靈活。 1.Python語法直觀,適用於數據科學和後端開發。 2.JavaScript靈活,廣泛用於前端和服務器端編程。

本文展示了與許可證確保的後端的前端集成,並使用Next.js構建功能性Edtech SaaS應用程序。 前端獲取用戶權限以控制UI的可見性並確保API要求遵守角色庫

從C/C 轉向JavaScript需要適應動態類型、垃圾回收和異步編程等特點。 1)C/C 是靜態類型語言,需手動管理內存,而JavaScript是動態類型,垃圾回收自動處理。 2)C/C 需編譯成機器碼,JavaScript則為解釋型語言。 3)JavaScript引入閉包、原型鍊和Promise等概念,增強了靈活性和異步編程能力。

我使用您的日常技術工具構建了功能性的多租戶SaaS應用程序(一個Edtech應用程序),您可以做同樣的事情。 首先,什麼是多租戶SaaS應用程序? 多租戶SaaS應用程序可讓您從唱歌中為多個客戶提供服務
