layui/docs/component/index.md

290 lines
8.3 KiB
Markdown
Raw Normal View History

---
title: 组件构建器 component
toc: true
---
# 组件构建器 <sup>2.10+</sup>
> 组件构建器 `component` 是 2.10 版本新增的重要模块,旨在为 Layui 2 系列版本逐步构建统一 API 规范的组件。
<h2 id="api" lay-toc="{hot: true}">API</h2>
| API | 描述 |
| --- | --- |
| [layui.component(options)](#create) | 创建组件 |
<h3 id="create" lay-toc="{level: 2}">创建组件</h3>
`layui.component(options);`
feat: 重构 laytpl,增强对更多复杂模板结构的解析能力 (#2577) * feat: 重构 laytpl,增强对更多复杂模板结构的解析能力 * Squashed commit of the following: commit 6884f80378f7606366c73e75c45946acc5817c95 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 14:45:58 2025 +0800 release: v2.10.1 commit 8d643ad6dc910ab86a4883ffe27ca3626553f892 Merge: 5521e48c 213fe5a2 Author: corededitor <107152508+corededitor@users.noreply.github.com> Date: Wed Mar 19 14:24:50 2025 +0800 feat: Merge pull request #2566 from layui/feat/component feat: 优化 component, tabs 若干功能 commit 213fe5a2090a7aef26af71fb5a0d6dc517b9a915 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 14:15:39 2025 +0800 docs: 添加 component 文档中实验性选项标记 commit 5521e48c05cd496476729cd33c754961c78cd2ac Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 14:10:46 2025 +0800 fix: 修复 `body` 初始 `line-height` 无效的问题 (#2569) commit 8c7cf0f6069a44ce7160fb2d69549956471bd684 Author: 青崖 <33601030+bxjt123@users.noreply.github.com> Date: Wed Mar 19 14:10:08 2025 +0800 优化 checkbox 标签风格选中且禁用时的显示 (#2563) commit 23b21254d4c4be4fd7e99e17f60c991e874d22c0 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 14:04:44 2025 +0800 docs: Squashed commit of the following: commit 95a0503f415126edabefb2cc9646a59bcb0932f3 Merge: e6eb86ba 87ba4c43 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 14:03:13 2025 +0800 Merge branch 'main' into 2.x commit e6eb86bacb130fcf57b6407b0c426ca7f770b326 Author: morning-star <26325820+Sight-wcg@users.noreply.github.com> Date: Wed Mar 19 14:02:05 2025 +0800 docs(slider): 修正错别字 (#2578) commit 46f7a9783e039bdc0efded87640fdfab31209f67 Merge: df1fc4f4 c204590a Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Fri Mar 14 19:07:50 2025 +0800 Merge branch 'main' into 2.x commit df1fc4f419819317c012091691db1012d48d5800 Author: itletu <itletu@163.com> Date: Mon Mar 10 13:54:06 2025 +0800 docs: 更正 class 公共类文档错误 (#2544) | layui-border-box | 设置元素及其所有子元素均为 `box-sizing: border-box` 模型的容器 | commit 87ba4c4394884b794da84a3f1bc9ba786cf748e2 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 13:41:33 2025 +0800 docs(version): 优化 2.9.x 锚点 commit a0f533f0fdfa34dba83bfe81ffa366c051859947 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 13:37:29 2025 +0800 docs: 修复 tabs 文档示例异常问题 commit 0f0584e2edc94a6aa483f4b4136a05ed599b0fb4 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 13:35:00 2025 +0800 docs: 修复 tabs 文档中自定义事件示例重新点击 Preview 失效的问题 commit 172957d2433c3a592c387f5a9f394734b4b127c0 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 13:29:09 2025 +0800 docs: 优化文档中的用词细节 (#2571) commit 094be4ddcccbb18caa696af65083562960929437 Author: letianpailove <113023596+letianpailove@users.noreply.github.com> Date: Wed Mar 19 13:28:46 2025 +0800 fix: 更正 class 公共类文档错误 (#2562) commit 53ded26cb96009330977320b5991bbcd17468eb7 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Sun Mar 16 00:15:25 2025 +0800 fix: 优化 tabs 重载时未按照传入的 closable 正确渲染可关闭状态 commit bd892bf87effa582bf8e3655c710d52f4066b2a5 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Sun Mar 16 00:15:17 2025 +0800 feat(component): 新增 cache 原型方法,用于元素缓存操作 commit 6ccc5a453d250537117646e8f9fe751153fd91a3 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Sun Mar 16 00:14:18 2025 +0800 fix(component): 优化元素 lay-options 属性上的配置在重载时的优先级 commit 79b0a56f506b0553fa67e4ce7467a21d4d8660ce Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Sun Mar 16 00:13:55 2025 +0800 fix(component): 修复 reload 时传入的选项未正确合并的问题 * refactor(laytpl): 优化代码细节 * docs: 重写 laytpl 模块文档
2025-03-27 23:55:04 +08:00
- 参数 `options` : 基础属性选项。[#详见属性](#options)
2025-03-05 19:27:06 +08:00
该方法返回一个对象,包含用于组件对外的基础接口,如:组件渲染、重载、事件操作,及构造函数等等。用法示例:
```js
/**
* tabs
* 标签页组件
*/
layui.define('component', function(exports) {
// 创建组件
var component = layui.component({
name: 'tabs', // 组件名称
config: { // 组件默认配置项
// …
},
render: function() { // 组件渲染逻辑
// …
},
// 其他选项
});
// 将创建组件时返回的 `component` 对象作为组件的接口输出
// 组件将继承通用的基础接口,如 render, reload, set 等方法
exports(component.CONST.MOD_NAME, component);
});
```
feat: 重构 laytpl,增强对更多复杂模板结构的解析能力 (#2577) * feat: 重构 laytpl,增强对更多复杂模板结构的解析能力 * Squashed commit of the following: commit 6884f80378f7606366c73e75c45946acc5817c95 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 14:45:58 2025 +0800 release: v2.10.1 commit 8d643ad6dc910ab86a4883ffe27ca3626553f892 Merge: 5521e48c 213fe5a2 Author: corededitor <107152508+corededitor@users.noreply.github.com> Date: Wed Mar 19 14:24:50 2025 +0800 feat: Merge pull request #2566 from layui/feat/component feat: 优化 component, tabs 若干功能 commit 213fe5a2090a7aef26af71fb5a0d6dc517b9a915 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 14:15:39 2025 +0800 docs: 添加 component 文档中实验性选项标记 commit 5521e48c05cd496476729cd33c754961c78cd2ac Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 14:10:46 2025 +0800 fix: 修复 `body` 初始 `line-height` 无效的问题 (#2569) commit 8c7cf0f6069a44ce7160fb2d69549956471bd684 Author: 青崖 <33601030+bxjt123@users.noreply.github.com> Date: Wed Mar 19 14:10:08 2025 +0800 优化 checkbox 标签风格选中且禁用时的显示 (#2563) commit 23b21254d4c4be4fd7e99e17f60c991e874d22c0 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 14:04:44 2025 +0800 docs: Squashed commit of the following: commit 95a0503f415126edabefb2cc9646a59bcb0932f3 Merge: e6eb86ba 87ba4c43 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 14:03:13 2025 +0800 Merge branch 'main' into 2.x commit e6eb86bacb130fcf57b6407b0c426ca7f770b326 Author: morning-star <26325820+Sight-wcg@users.noreply.github.com> Date: Wed Mar 19 14:02:05 2025 +0800 docs(slider): 修正错别字 (#2578) commit 46f7a9783e039bdc0efded87640fdfab31209f67 Merge: df1fc4f4 c204590a Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Fri Mar 14 19:07:50 2025 +0800 Merge branch 'main' into 2.x commit df1fc4f419819317c012091691db1012d48d5800 Author: itletu <itletu@163.com> Date: Mon Mar 10 13:54:06 2025 +0800 docs: 更正 class 公共类文档错误 (#2544) | layui-border-box | 设置元素及其所有子元素均为 `box-sizing: border-box` 模型的容器 | commit 87ba4c4394884b794da84a3f1bc9ba786cf748e2 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 13:41:33 2025 +0800 docs(version): 优化 2.9.x 锚点 commit a0f533f0fdfa34dba83bfe81ffa366c051859947 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 13:37:29 2025 +0800 docs: 修复 tabs 文档示例异常问题 commit 0f0584e2edc94a6aa483f4b4136a05ed599b0fb4 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 13:35:00 2025 +0800 docs: 修复 tabs 文档中自定义事件示例重新点击 Preview 失效的问题 commit 172957d2433c3a592c387f5a9f394734b4b127c0 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 13:29:09 2025 +0800 docs: 优化文档中的用词细节 (#2571) commit 094be4ddcccbb18caa696af65083562960929437 Author: letianpailove <113023596+letianpailove@users.noreply.github.com> Date: Wed Mar 19 13:28:46 2025 +0800 fix: 更正 class 公共类文档错误 (#2562) commit 53ded26cb96009330977320b5991bbcd17468eb7 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Sun Mar 16 00:15:25 2025 +0800 fix: 优化 tabs 重载时未按照传入的 closable 正确渲染可关闭状态 commit bd892bf87effa582bf8e3655c710d52f4066b2a5 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Sun Mar 16 00:15:17 2025 +0800 feat(component): 新增 cache 原型方法,用于元素缓存操作 commit 6ccc5a453d250537117646e8f9fe751153fd91a3 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Sun Mar 16 00:14:18 2025 +0800 fix(component): 优化元素 lay-options 属性上的配置在重载时的优先级 commit 79b0a56f506b0553fa67e4ce7467a21d4d8660ce Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Sun Mar 16 00:13:55 2025 +0800 fix(component): 修复 reload 时传入的选项未正确合并的问题 * refactor(laytpl): 优化代码细节 * docs: 重写 laytpl 模块文档
2025-03-27 23:55:04 +08:00
<h3 id="options" lay-toc="{level: 2}">属性选项</h3>
<div>
{{- d.include("/component/detail/options.md") }}
</div>
<h2 id="export" lay-toc="{}">基础接口 🔥</h2>
通过 `component` 模块创建的组件,均会继承内部定义的「基础对外接口」和「组件渲染的通用选项」。
| 接口 | 描述 |
| --- | --- |
| [component.render(options)](#render) | 组件渲染 |
| [component.reload(id, options)](#reload) | 组件重载 |
| [component.set(options)](#set) | 设置组件渲染时的全局配置项 |
| [component.on(\'event(filter)\', callback)](#on) | 组件的自定义事件 |
| [component.getThis(id)](#getThis) | 获取指定组件的实例对象 |
| component.index | 获得组件的自增索引 |
| component.config | 获得组件渲染时的全局配置项。一般通过 `set` 方法设置 |
| component.cache | 获得组件的缓存数据集。如组件实例 ID 集 |
| [component.CONST](#CONST) | 获得组件的通用常量集。如 `MOD_NAME` 等 |
| [component.Class](#Class) | 获得组件的构造函数。一般用于扩展原型方法 |
2025-03-05 19:27:06 +08:00
> 😊 注:上表中的 `component` 为组件的基础对象,实际使用时,请根据实组件名称进行替换。如 `tabs` 组件,对应的接口则为:`tabs.render(options)` `tabs.on('event(filter)', callback)` 等。
<h3 id="render" lay-toc="{level: 2}">组件渲染</h3>
`component.render(options)`
- 参数 `options` : 组件渲染的配置项。可继承的通用选项见下表:
| 选项 | 描述 |
| --- | --- |
feat: 重构 laytpl,增强对更多复杂模板结构的解析能力 (#2577) * feat: 重构 laytpl,增强对更多复杂模板结构的解析能力 * Squashed commit of the following: commit 6884f80378f7606366c73e75c45946acc5817c95 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 14:45:58 2025 +0800 release: v2.10.1 commit 8d643ad6dc910ab86a4883ffe27ca3626553f892 Merge: 5521e48c 213fe5a2 Author: corededitor <107152508+corededitor@users.noreply.github.com> Date: Wed Mar 19 14:24:50 2025 +0800 feat: Merge pull request #2566 from layui/feat/component feat: 优化 component, tabs 若干功能 commit 213fe5a2090a7aef26af71fb5a0d6dc517b9a915 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 14:15:39 2025 +0800 docs: 添加 component 文档中实验性选项标记 commit 5521e48c05cd496476729cd33c754961c78cd2ac Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 14:10:46 2025 +0800 fix: 修复 `body` 初始 `line-height` 无效的问题 (#2569) commit 8c7cf0f6069a44ce7160fb2d69549956471bd684 Author: 青崖 <33601030+bxjt123@users.noreply.github.com> Date: Wed Mar 19 14:10:08 2025 +0800 优化 checkbox 标签风格选中且禁用时的显示 (#2563) commit 23b21254d4c4be4fd7e99e17f60c991e874d22c0 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 14:04:44 2025 +0800 docs: Squashed commit of the following: commit 95a0503f415126edabefb2cc9646a59bcb0932f3 Merge: e6eb86ba 87ba4c43 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 14:03:13 2025 +0800 Merge branch 'main' into 2.x commit e6eb86bacb130fcf57b6407b0c426ca7f770b326 Author: morning-star <26325820+Sight-wcg@users.noreply.github.com> Date: Wed Mar 19 14:02:05 2025 +0800 docs(slider): 修正错别字 (#2578) commit 46f7a9783e039bdc0efded87640fdfab31209f67 Merge: df1fc4f4 c204590a Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Fri Mar 14 19:07:50 2025 +0800 Merge branch 'main' into 2.x commit df1fc4f419819317c012091691db1012d48d5800 Author: itletu <itletu@163.com> Date: Mon Mar 10 13:54:06 2025 +0800 docs: 更正 class 公共类文档错误 (#2544) | layui-border-box | 设置元素及其所有子元素均为 `box-sizing: border-box` 模型的容器 | commit 87ba4c4394884b794da84a3f1bc9ba786cf748e2 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 13:41:33 2025 +0800 docs(version): 优化 2.9.x 锚点 commit a0f533f0fdfa34dba83bfe81ffa366c051859947 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 13:37:29 2025 +0800 docs: 修复 tabs 文档示例异常问题 commit 0f0584e2edc94a6aa483f4b4136a05ed599b0fb4 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 13:35:00 2025 +0800 docs: 修复 tabs 文档中自定义事件示例重新点击 Preview 失效的问题 commit 172957d2433c3a592c387f5a9f394734b4b127c0 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Wed Mar 19 13:29:09 2025 +0800 docs: 优化文档中的用词细节 (#2571) commit 094be4ddcccbb18caa696af65083562960929437 Author: letianpailove <113023596+letianpailove@users.noreply.github.com> Date: Wed Mar 19 13:28:46 2025 +0800 fix: 更正 class 公共类文档错误 (#2562) commit 53ded26cb96009330977320b5991bbcd17468eb7 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Sun Mar 16 00:15:25 2025 +0800 fix: 优化 tabs 重载时未按照传入的 closable 正确渲染可关闭状态 commit bd892bf87effa582bf8e3655c710d52f4066b2a5 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Sun Mar 16 00:15:17 2025 +0800 feat(component): 新增 cache 原型方法,用于元素缓存操作 commit 6ccc5a453d250537117646e8f9fe751153fd91a3 Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Sun Mar 16 00:14:18 2025 +0800 fix(component): 优化元素 lay-options 属性上的配置在重载时的优先级 commit 79b0a56f506b0553fa67e4ce7467a21d4d8660ce Author: 贤心 <3277200+sentsim@users.noreply.github.com> Date: Sun Mar 16 00:13:55 2025 +0800 fix(component): 修复 reload 时传入的选项未正确合并的问题 * refactor(laytpl): 优化代码细节 * docs: 重写 laytpl 模块文档
2025-03-27 23:55:04 +08:00
| elem | 组件渲染指定的目标元素选择器或 DOM 对象 |
| id | 组件渲染的唯一实例 ID |
| show | 是否初始即渲染组件。通常结合创建组件设定的 `isRenderOnEvent` 选项决定是否启用 |
更多渲染时的选项则由各组件内部单独定义,具体可查阅各组件对应的文档。
```js
// 以 tabs 组件为例
// 渲染
tabs.render({
elem: '#id',
// …
});
```
<h3 id="reload" lay-toc="{level: 2}">组件重载</h3>
`component.reload(id, options)`
- 参数 `id` : 组件实例 ID。
- 参数 `options` : 组件重载的配置项。
该方法可实现对组件的完整重载。部分组件通常还提供了「仅数据重载」,具体可参考各组件对应的文档。
```js
// 以 tabs 组件为例
// 重载 tabs 组件实例
tabs.reload('id', {
// …
})
```
<h3 id="set" lay-toc="{level: 2}">全局设置</h3>
`component.set(options)`
- 参数 `options` : 组件渲染的配置项。
该方法用于全局设置组件渲染时的默认配置项,需在组件渲染之前执行。
```js
// 以 tabs 组件为例
// 全局设置。后续所有渲染均会生效,除非对选项进行覆盖
tabs.set({
trigger: 'mouseenter' // 默认的触发事件
// …
});
// 渲染实例 1
tabs.render({ id: 'id1'}); // 继承全局设置
// 渲染实例 2
tabs.render({
id: 'id2',
trigger: 'click' // 覆盖全局的触发事件
});
```
<h3 id="on" lay-toc="{level: 2}">事件定义</h3>
`component.on('event(id)', callback)`
2025-03-05 19:27:06 +08:00
- 参数 `event(id)` : 是事件的特定结构。 `event` 为事件名,支持的事件见各组件列表。`id` 为组件的实例 ID。
- 参数 `callback` : 事件回调函数。返回的参数由各组件内部单独定义。
具体事件一般由组件内部单独定义,具体可查看各组件对应的文档。
```js
// 以 tabs 组件为例:
// 组件渲染成功后的事件
tabs.on('afterRender(id)', function(data) {
console.log(obj);
});
```
<h3 id="getThis" lay-toc="{level: 2}">获取实例</h3>
`component.getThis(id)`
- 参数 `id` : 组件的实例 ID。
该方法可获取组件渲染时对应的实例,以调用组件内部的原型方法,一般用于在外部对组件进行扩展或重构。
```js
// 以 tabs 组件为例
var tabInstance = tabs.getThis('id');
// 调用内部的标签滚动方法
tabInstance.roll();
```
<h3 id="CONST" lay-toc="{level: 2}">基础常量</h3>
`component.CONST`
获取组件的通用常量集,一般存放固定字符,如类名等。
```js
// 基础常量如下
component.CONST.MOD_NAME; // 组件名称
component.CONST.MOD_INDEX; // 组件自增索引
component.CONST.CLASS_THIS; // layui-this
component.CONST.CLASS_SHOW; // layui-show
component.CONST.CLASS_HIDE; // layui-hide
component.CONST.CLASS_HIDEV; // layui-hide-v
component.CONST.CLASS_DISABLED; // layui-disabled
component.CONST.CLASS_NONE; // layui-none
// 更多常量一般在各组件内部单独定义,以 tabs 组件为例
tabs.CONST.ELEM; // layui-tabs
```
<h3 id="extend" lay-toc="{level: 2}">扩展接口</h3>
除上述「基础接口」外,你也可以对接口进行任意扩展,如:
```js
/**
* 定义组件
*/
layui.define('component', function(exports) {
// 创建组件
var component = layui.component({
name: 'test',
// …
});
// 扩展组件接口
layui.$.extend(component, {
// 以扩展一个关闭组件面板的接口为例
close: function(id) {
var that = component.getThis(id);
if(!that) return this;
that.remove(obj); // 调用原型中的 remove 方法
}
});
// 输出组件接口
exports(component.CONST.MOD_NAME, component);
});
```
```js
/**
* 使用组件(以上述定义的 test 组件为例)
*/
layui.use('test', function() {
var test = layui.test;
// 渲染组件
test.render({
elem: '#id',
id: 'test-1'
});
// 关闭组件面板(通常在某个事件中使用)
test.close('test-1');
});
```
<h3 id="Class" lay-toc="{level: 2}">扩展原型</h3>
`component.Class`
2025-03-05 19:27:06 +08:00
当通过 `layui.component()` 方法创建一个新的组件时,通常需借助 `Class` 构造函数扩展组件原型,以灵活实现组件的个性化定制。但一般不推荐重写 `component.js` 原型中已经定义的基础方法,如:`init, reload, cache`
```
/**
* 定义组件
*/
layui.define('component', function(exports) {
// 创建组件
var component = layui.component({
name: '', // 组件名称
// …
});
// 获取构造器
var Class = component.Class;
// 扩展原型
Class.prototype.xxx = function() {
// …
};
Class.prototype.aaa = function() {
// …
};
// 输出组件接口
exports(component.CONST.MOD_NAME, component);
});
```
2025-03-05 19:27:06 +08:00
通过 `Class` 构造函数也可以对某个组件的原型进行重构,但一般不推荐,因为这可能破坏组件的基础功能。
```
// 以 tabs 组件为例
var tabs = layui.tabs;
// 获得 tabs 组件构造函数
var Class = tabs.Class;
// 重构 tabs 组件内部的 xxx 方法(不推荐)
Class.prototype.xxx = function() {
// …
};
```
您也可以直接参考 tabs 组件源码中关于扩展原型的具体实践。
## 💖 心语
2025-03-05 19:27:06 +08:00
Layui 由于早前欠缺统筹性思维,很多组件自成一体,使得无法对组件进行很好的统一管理。随着版本的迭代,我们也一直在努力尝试改善这一问题,但很多时候,为了向下兼容而不得不保留许多旧有的特性。`component` 模块的初衷正是为了确保组件的一致性,如核心逻辑和 API 设计等,其目的也是为了让 2.x 系列版本尽可能地减少些遗憾,让 Layui 在既定的范式中保持前行。