亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

目錄
邱敬幃 Pardn Chiu
首頁 web前端 js教程 QuickUI:輕量級前端框架

QuickUI:輕量級前端框架

Dec 26, 2024 am 08:23 AM

QuickUI: Lightweight Frontend Framework

GitHub

(原名PDQuickUI,從0.6.0版本開始更名為QuickUI)

QuickUI是一個源自PDRenderKit的前端渲染框架,專注于增強前端框架功能。

通過集成虛擬DOM,重寫渲染邏輯,提高渲染效率,實現(xiàn)更快的數(shù)據(jù)觀察和自動更新。

該項目從 PDRenderKit 中刪除了原型擴展,以確保兼容性和性能,使其適合復(fù)雜的應(yīng)用程序。

它提供模塊和非模塊版本,并將 PDRenderKit 中的許可證從 GPL-3.0 更改為 MIT。

特征

  • 清晰的架構(gòu):將UI與數(shù)據(jù)邏輯分離,使其更易于維護。
  • 代碼簡潔:減少冗余代碼,增強可讀性。
  • 自動渲染:自動監(jiān)控數(shù)據(jù)變化和更新,最大限度地減少手動操作。
  • 輕量級:在小于 20kb 的文件大小內(nèi)保持完整功能。

安裝

  • 從 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
            }
        }
    });
    

概述

自動渲染:檢測到數(shù)據(jù)更改時自動重新加載。

屬性概述

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
    
  • 結(jié)果

    <!-- 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";
    
  • 結(jié)果

    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
            }
        }
    });
    

插入塊

> [!注意]
>確保在測試時禁用瀏覽器中的本地文件限制或使用實時服務(wù)器。

:小路

  • test.html

    <h1>{{ title }}</h1>
    
        const app = new QUI({
            id: "app",
            data: {
                title: "test"
            }
        });
    
    
  • index.html

        <h1>test</h1>
    
    
  • 結(jié)果

        const app = new QUI({
            id: "app",
            data: {
                html: "<b>innerHtml</b>"
            }
        });
    
    

循環(huán)渲染

:為了

  • index.html

            <b>innerHtml</b>
    
    
  • 結(jié)果

    <h1>path heading</h1>
    <p>path content</p>
    
  • 結(jié)果

        const app = new QUI({
            id: "app"
        });
    
    

條件渲染

  • index.html

        <h1>path heading</h1>
        <p>path content</p>
    
    
  • 結(jié)果:標題 = 1

        <ul>
            <li>{{ item }} {{ CALC(index + 1) }}</li>
        </ul>
    
        const app = new QUI({
            id: "app",
            data: {
                ary: ["test1", "test2", "test3"]
            }
        });
    
    
  • 結(jié)果:heading = null && isH2 = true

        <li>
    

Nest loop

  • index.html

      <li> {{ key }}: {{ val.name }}
      • {{ item.name }}
        • {{ CALC(index1 + 1) }}. {{ item1.name }} - ${{ item1.price }}
    const app = new QUI({ id: "app", data: { obj: { food: { name: "Food", ary: [ { name: 'Snacks', ary1: [ { name: 'Potato Chips', price: 10 }, { name: 'Chocolate', price: 8 } ] }, { name: 'Beverages', ary1: [ { name: 'Juice', price: 5 }, { name: 'Tea', price: 3 } ] } ] }, home: { name: 'Home', ary: [ { name: 'Furniture', ary1: [ { name: 'Sofa', price: 300 }, { name: 'Table', price: 150 } ] }, { name: 'Decorations', ary1: [ { name: 'Picture Frame', price: 20 }, { name: 'Vase', price: 15 } ] } ] } } } });
  • 結(jié)果:標題 = 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>
    
    
  • 結(jié)果: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>
    
    
  • 結(jié)果

        <h2>test </h2>
    
    

綁定

    <h3>test 3</h3>

活動

    <h4>test </h4>

CSS

> [!注意]
>支持使用:[CSS屬性]進行簡單設(shè)置,直接將數(shù)據(jù)綁定到樣式屬性。

  • index.html

        const test = new QUI({
            id: "app",
            data: {
                hint: "hint 123",
                title: "test 123"
            },
            render: () => {
                return `
                    "{{ hint }}",
                    h1 {
                        style: "background: red;", 
                        children: [ 
                            "{{ title }}"
                        ]
                    }`
            }
        })
    
    
  • 結(jié)果:

        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);
                }
            }
        });
    
    
  • 結(jié)果

        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"
            }
        });
    
    
  • 結(jié)果

        test
    
    

上() / 下()

  • index.html

        <p>Total: {{ LENGTH(array) }}</p>
    
        const app = new QUI({
            id: "app",
            data: {
                array: [1, 2, 3, 4]
            }
        });
    
    
  • 結(jié)果

        <p>Total: 4</p>
    
    

日期(數(shù)字,格式)

  • index.html

        <p>calc: {{ CALC(num * 10) }}</p>
    
        const app = new QUI({
            id: "app",
            data: {
                num: 1
            }
        });
    
    
  • 結(jié)果

        <p>calc: 10</p>
    
    

延遲加載

:延遲加載

  • index.html

        <p>{{ UPPER(test1) }} {{ LOWER(test2) }}</p>
    
        const app = new QUI({
            id: "app",
            data: {
                test1: "upper",
                test2: "LOWER"
            }
        });
    
    
  • 結(jié)果

        <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>
    
    
  • 結(jié)果

        <img>
    
        const app = new QUI({
            id: "app",
            data: {
                image: "test.jpg"
            },
            option: {
                lazyload: true // Enable image lazy loading: true|false (default: true)
            }
        });
    
    

i18n

> [!注意]
>如果format是對象,則直接配置多語言內(nèi)容。
>如果格式是字符串,則通過 fetch 動態(tài)加載語言文件。

  • en.json

        <img src="test.jpg">
    
    
  • index.html

    
    
  • 結(jié)果 i18nLang = zh

        const app = new QUI({
            id: "app",
            data: {
                svg: "test.svg",
            },
            option: {
                svg: true  // Enable SVG file transformation: true|false (default: true)
            }
        });
    
    
  • 結(jié)果 i18nLang = en

    
    

生命周期掛鉤

{
    "greeting": "Hello",
    "username": "Username"
}

數(shù)據(jù)檢索

npm i @pardnchiu/quickui

創(chuàng)作者

邱敬幃 Pardn Chiu

執(zhí)照

此項目已獲得專有許可證許可。

您只能根據(jù)最終用戶許可協(xié)議 (EULA) 中指定的條款使用、安裝和運行此軟件。


?? 2024 邱敬幃 Pardn Chiu

以上是QuickUI:輕量級前端框架的詳細內(nèi)容。更多信息請關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

本站聲明
本文內(nèi)容由網(wǎng)友自發(fā)貢獻,版權(quán)歸原作者所有,本站不承擔(dān)相應(yīng)法律責(zé)任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請聯(lián)系admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費脫衣服圖片

Undresser.AI Undress

Undresser.AI Undress

人工智能驅(qū)動的應(yīng)用程序,用于創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用于從照片中去除衣服的在線人工智能工具。

Clothoff.io

Clothoff.io

AI脫衣機

Video Face Swap

Video Face Swap

使用我們完全免費的人工智能換臉工具輕松在任何視頻中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的代碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

功能強大的PHP集成開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級代碼編輯軟件(SublimeText3)

垃圾收集如何在JavaScript中起作用? 垃圾收集如何在JavaScript中起作用? Jul 04, 2025 am 12:42 AM

JavaScript的垃圾回收機制通過標記-清除算法自動管理內(nèi)存,以減少內(nèi)存泄漏風(fēng)險。引擎從根對象出發(fā)遍歷并標記活躍對象,未被標記的則被視為垃圾并被清除。例如,當(dāng)對象不再被引用(如將變量設(shè)為null),它將在下一輪回收中被釋放。常見的內(nèi)存泄漏原因包括:①未清除的定時器或事件監(jiān)聽器;②閉包中對外部變量的引用;③全局變量持續(xù)持有大量數(shù)據(jù)。V8引擎通過分代回收、增量標記、并行/并發(fā)回收等策略優(yōu)化回收效率,降低主線程阻塞時間。開發(fā)時應(yīng)避免不必要的全局引用、及時解除對象關(guān)聯(lián),以提升性能與穩(wěn)定性。

如何在node.js中提出HTTP請求? 如何在node.js中提出HTTP請求? Jul 13, 2025 am 02:18 AM

在Node.js中發(fā)起HTTP請求有三種常用方式:使用內(nèi)置模塊、axios和node-fetch。1.使用內(nèi)置的http/https模塊無需依賴,適合基礎(chǔ)場景,但需手動處理數(shù)據(jù)拼接和錯誤監(jiān)聽,例如用https.get()獲取數(shù)據(jù)或通過.write()發(fā)送POST請求;2.axios是基于Promise的第三方庫,語法簡潔且功能強大,支持async/await、自動JSON轉(zhuǎn)換、攔截器等,推薦用于簡化異步請求操作;3.node-fetch提供類似瀏覽器fetch的風(fēng)格,基于Promise且語法簡單

JavaScript數(shù)據(jù)類型:原始與參考 JavaScript數(shù)據(jù)類型:原始與參考 Jul 13, 2025 am 02:43 AM

JavaScript的數(shù)據(jù)類型分為原始類型和引用類型。原始類型包括string、number、boolean、null、undefined和symbol,其值不可變且賦值時復(fù)制副本,因此互不影響;引用類型如對象、數(shù)組和函數(shù)存儲的是內(nèi)存地址,指向同一對象的變量會相互影響。判斷類型可用typeof和instanceof,但需注意typeofnull的歷史問題。理解這兩類差異有助于編寫更穩(wěn)定可靠的代碼。

JavaScript時間對象,某人構(gòu)建了一個eactexe,在Google Chrome上更快的網(wǎng)站等等 JavaScript時間對象,某人構(gòu)建了一個eactexe,在Google Chrome上更快的網(wǎng)站等等 Jul 08, 2025 pm 02:27 PM

JavaScript開發(fā)者們,大家好!歡迎閱讀本周的JavaScript新聞!本周我們將重點關(guān)注:Oracle與Deno的商標糾紛、新的JavaScript時間對象獲得瀏覽器支持、GoogleChrome的更新以及一些強大的開發(fā)者工具。讓我們開始吧!Oracle與Deno的商標之爭Oracle試圖注冊“JavaScript”商標的舉動引發(fā)爭議。Node.js和Deno的創(chuàng)建者RyanDahl已提交請愿書,要求取消該商標,他認為JavaScript是一個開放標準,不應(yīng)由Oracle

React與Angular vs Vue:哪個JS框架最好? React與Angular vs Vue:哪個JS框架最好? Jul 05, 2025 am 02:24 AM

選哪個JavaScript框架最好?答案是根據(jù)需求選擇最適合的。1.React靈活自由,適合需要高度定制、團隊有架構(gòu)能力的中大型項目;2.Angular提供完整解決方案,適合企業(yè)級應(yīng)用和長期維護的大項目;3.Vue上手簡單,適合中小型項目或快速開發(fā)。此外,是否已有技術(shù)棧、團隊規(guī)模、項目生命周期及是否需要SSR也都是選擇框架的重要因素??傊?,沒有絕對最好的框架,適合自己需求的就是最佳選擇。

立即在JavaScript中立即調(diào)用功能表達式(IIFE) 立即在JavaScript中立即調(diào)用功能表達式(IIFE) Jul 04, 2025 am 02:42 AM

IIFE(ImmediatelyInvokedFunctionExpression)是一種在定義后立即執(zhí)行的函數(shù)表達式,用于變量隔離和避免污染全局作用域。它通過將函數(shù)包裹在括號中使其成為表達式,并緊隨其后的一對括號來調(diào)用,如(function(){/code/})();。其核心用途包括:1.避免變量沖突,防止多個腳本間的命名重復(fù);2.創(chuàng)建私有作用域,使函數(shù)內(nèi)部變量不可見;3.模塊化代碼,便于初始化工作而不暴露過多變量。常見寫法包括帶參數(shù)傳遞的版本和ES6箭頭函數(shù)版本,但需注意:必須使用表達式、結(jié)

什么是緩存API?如何與服務(wù)人員使用? 什么是緩存API?如何與服務(wù)人員使用? Jul 08, 2025 am 02:43 AM

CacheAPI是瀏覽器提供的一種緩存網(wǎng)絡(luò)請求的工具,常與ServiceWorker配合使用,以提升網(wǎng)站性能和離線體驗。1.它允許開發(fā)者手動存儲如腳本、樣式表、圖片等資源;2.可根據(jù)請求匹配緩存響應(yīng);3.支持刪除特定緩存或清空整個緩存;4.通過ServiceWorker監(jiān)聽fetch事件實現(xiàn)緩存優(yōu)先或網(wǎng)絡(luò)優(yōu)先等策略;5.常用于離線支持、加快重復(fù)訪問速度、預(yù)加載關(guān)鍵資源及后臺更新內(nèi)容;6.使用時需注意緩存版本控制、存儲限制及與HTTP緩存機制的區(qū)別。

處理諾言:鏈接,錯誤處理和承諾在JavaScript中 處理諾言:鏈接,錯誤處理和承諾在JavaScript中 Jul 08, 2025 am 02:40 AM

Promise是JavaScript中處理異步操作的核心機制,理解鏈式調(diào)用、錯誤處理和組合器是掌握其應(yīng)用的關(guān)鍵。1.鏈式調(diào)用通過.then()返回新Promise實現(xiàn)異步流程串聯(lián),每個.then()接收上一步結(jié)果并可返回值或Promise;2.錯誤處理應(yīng)統(tǒng)一使用.catch()捕獲異常,避免靜默失敗,并可在catch中返回默認值繼續(xù)流程;3.組合器如Promise.all()(全成功才成功)、Promise.race()(首個完成即返回)和Promise.allSettled()(等待所有完成)

See all articles