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工具

Undress AI Tool
免费脱衣服图片

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

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

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

JavaScript的作用域决定变量可访问范围,分为全局、函数和块级作用域;上下文决定this的指向,依赖函数调用方式。1.作用域包括全局作用域(任何地方可访问)、函数作用域(仅函数内有效)、块级作用域(let和const在{}内有效)。2.执行上下文包含变量对象、作用域链和this的值,this在普通函数指向全局或undefined,在方法调用指向调用对象,在构造函数指向新对象,也可用call/apply/bind显式指定。3.闭包是指函数访问并记住外部作用域变量,常用于封装和缓存,但可能引发

获取选中的单选按钮值的核心方法有两种。1.使用querySelector直接获取选中项,通过input[name="your-radio-name"]:checked选择器获取选中的元素并读取其value属性,适合现代浏览器且代码简洁;2.使用document.getElementsByName遍历查找,通过循环NodeList找到第一个checked的radio并获取其值,适合兼容旧浏览器或需要手动控制流程的场景;此外需注意name属性拼写、处理未选中情况以及动态加载内容时

Vue3中CompositionAPI更适合复杂逻辑和类型推导,OptionsAPI适合简单场景和初学者;1.OptionsAPI按data、methods等选项组织代码,结构清晰但复杂组件易碎片化;2.CompositionAPI用setup集中相关逻辑,利于维护和复用;3.CompositionAPI通过composable函数实现无冲突、可参数化的逻辑复用,优于mixin;4.CompositionAPI对TypeScript支持更好,类型推导更精准;5.两者性能和打包体积无显着差异;6.

JavaScript的WebWorkers和JavaThreads在并发处理上有本质区别。1.JavaScript采用单线程模型,WebWorkers是浏览器提供的独立线程,适合执行不阻塞UI的耗时任务,但不能操作DOM;2.Java从语言层面支持真正的多线程,通过Thread类创建,适用于复杂并发逻辑和服务器端处理;3.WebWorkers使用postMessage()与主线程通信,安全隔离性强;Java线程可共享内存,需注意同步问题;4.WebWorkers更适合前端并行计算,如图像处理,而

调试JavaScript复杂应用需系统化使用工具。1.设断点及条件断点拦截可疑流程,如函数入口、循环、异步回调前并按条件过滤;2.启用Blackboxing功能屏蔽第三方库干扰;3.结合环境判断使用debugger语句控制调试入口;4.通过CallStack追溯调用链路,分析执行路径与变量状态,从而高效定位问题根源。

类型强制转换是JavaScript中自动将一种类型的值转为另一种类型的行为,常见场景包括:1.使用 运算符时,若其中一边为字符串,另一边也会被转为字符串,如'5' 5结果为"55";2.布尔上下文中非布尔值会被隐式转为布尔类型,如空字符串、0、null、undefined等被视为false;3.null参与数值运算会转为0,而undefined会转为NaN;4.可通过显式转换函数如Number()、String()、Boolean()避免隐式转换带来的问题。掌握这些规则有助于

在JavaScript中格式化日期可通过原生方法或第三方库实现。1.使用原生Date对象拼接:通过getFullYear、getMonth、getDate等方法获取日期部分,手动拼接成YYYY-MM-DD等格式,适合轻量需求且不依赖第三方库;2.使用toLocaleDateString方法:可按本地习惯输出如MM/DD/YYYY格式,支持多语言但格式可能因环境不同而不一致;3.使用第三方库如day.js或date-fns:提供简洁语法和丰富功能,适合频繁操作或需要扩展性时使用,例如dayjs()

初始化项目并创建package.json;2.创建带shebang的入口脚本index.js;3.在package.json中通过bin字段注册命令;4.使用yargs等库解析命令行参数;5.用npmlink本地测试;6.添加帮助、版本和选项增强体验;7.可选地通过npmpublish发布;8.可选地用yargs实现自动补全;最终通过合理结构和用户体验设计打造实用的CLI工具,完成自动化任务或分发小工具,以完整句⼦结束。
