代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Layui 开发使用文档 - 入门指南</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<script>
; !function () { self !== parent && (location.href = "https://www.baidu.com/") }();
</script>
<link rel="stylesheet" href="layui.css"
media="all">
<link rel="stylesheet" href="global.css"
media="all">
</head>
<style>
.site-dir {
z-index: 19891015;
position: fixed;
top: 513px;
left: 88%;
margin-left: -15px;
display: block;
box-shadow: none;
border: 1px solid #d2d2d2;
padding: 0.5%;
}
</style>
<body>
<div class="layui-header header header-doc">
<div class="layui-container">
<a class="logo"
href="#"
tppabs="https://www.layui.com/">
<img src="logo.png" tppabs="https://res.layui.com/static/images/layui/logo.png" alt="layui">
</a>
<div class="layui-form layui-hide-xs component" lay-filter="LAY-site-header-component"></div>
<div class="layui-hide-xs site-notice"></div>
<ul class="layui-nav" id="LAY_NAV_TOP">
<li class="layui-nav-item layui-this">
<a href="index.html">文档</a>
</li>
<li class="layui-nav-item ">
<a href="demo/index.htm"
tppabs="demo/index.htm">示例</a>
</li>
</ul>
</div>
</div>
<!-- 让IE8/9支持媒体查询,从而兼容栅格 -->
<!--[if lt IE 9]>
<script src="html5.min.js" tppabs="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
<script src="respond.min.js" tppabs="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<ul class="site-dir">
<div class="layui-layer-title" style="cursor: move;">目录</div>
<li><a href="#get"><cite>获得 layui</cite></a></li>
<li><a href="#quickstart"><cite>快速上手</cite></a></li>
<li><a href="#classical"><cite>何为「经典」</cite></a></li>
<li><a href="#modules"><cite>建立模块入口</cite></a></li>
<li><a href="#extmodules"><cite>管理扩展模块</cite></a></li>
</ul>
<div class="layui-container layui-row">
<div class="layui-col-md3">
<div class="layui-panel site-menu">
<ul class="layui-menu layui-menu-lg">
<li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
<div class="layui-menu-body-title">
基础说明
</div>
<hr>
<ul>
<li class="layui-menu-item-checked2">
<div class="layui-menu-body-title">
<a href="index.html" tppabs="https://www.layui.com/doc/">
<span>开始使用 </span>
<span class="layui-font-12 layui-font-gray">Getting Started</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="infrastructure.html" tppabs="https://www.layui.com/doc/base/infrastructure.html">
<span>底层方法 </span>
<span class="layui-font-12 layui-font-gray">基础支撑</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="element.html" tppabs="https://www.layui.com/doc/base/element.html">
<span>页面元素 </span>
<span class="layui-font-12 layui-font-gray">规范 公共类 属性</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="modules.html" tppabs="https://www.layui.com/doc/base/modules.html">
<span>模块规范 </span>
<span class="layui-font-12 layui-font-gray">使用 扩展</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="faq.html" tppabs="https://www.layui.com/doc/base/faq.html">
<span>常见问题 </span>
<span class="layui-font-12 layui-font-gray">FAQ</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="changelog.html" tppabs="https://www.layui.com/doc/base/changelog.html">
<span>更新日志 </span>
<span class="layui-font-12 layui-font-gray">changelog</span>
<span class="layui-badge-dot"></span>
</a>
</div>
</li>
</ul>
</li>
<li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
<div class="layui-menu-body-title">
页面元素
</div>
<hr>
<ul>
<li class="">
<div class="layui-menu-body-title">
<a href="layout.html" tppabs="https://www.layui.com/doc/element/layout.html">
<span>布局 </span>
<span class="layui-font-12 layui-font-gray">栅格 后台管理布局</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="color.html" tppabs="https://www.layui.com/doc/element/color.html">
<span>颜色 </span>
<span class="layui-font-12 layui-font-gray">主色调 颜色搭配</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="icon.html" tppabs="https://www.layui.com/doc/element/icon.html">
<span>图标 </span>
<span class="layui-font-12 layui-font-gray">iconfont 字体图标</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="anim.html" tppabs="https://www.layui.com/doc/element/anim.html">
<span>动画 </span>
<span class="layui-font-12 layui-font-gray">内置 CSS3 动画</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="button.html" tppabs="https://www.layui.com/doc/element/button.html">
<span>按钮 </span>
<span class="layui-font-12 layui-font-gray">button</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="form.html" tppabs="https://www.layui.com/doc/element/form.html">
<span>表单 </span>
<span class="layui-font-12 layui-font-gray">form 元素集合</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="nav.html" tppabs="https://www.layui.com/doc/element/nav.html">
<span>导航 </span>
<span class="layui-font-12 layui-font-gray">nav 面包屑</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="menu.html" tppabs="https://www.layui.com/doc/element/menu.html">
<span>菜单 </span>
<span class="layui-font-12 layui-font-gray">menu 基础菜单</span>
<span class="layui-badge-dot"></span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="tab.html" tppabs="https://www.layui.com/doc/element/tab.html">
<span>选项卡 </span>
<span class="layui-font-12 layui-font-gray">Tabs 切换</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="progress.html" tppabs="https://www.layui.com/doc/element/progress.html">
<span>进度条 </span>
<span class="layui-font-12 layui-font-gray">progress</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="panel.html" tppabs="https://www.layui.com/doc/element/panel.html">
<span>面板 </span>
<span class="layui-font-12 layui-font-gray">panel 卡片 折叠</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="table.html" tppabs="https://www.layui.com/doc/element/table.html">
<span>表格 </span>
<span class="layui-font-12 layui-font-gray">静态 table</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="badge.html" tppabs="https://www.layui.com/doc/element/badge.html">
<span>徽章 </span>
<span class="layui-font-12 layui-font-gray">小圆点 小边框</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="timeline.html" tppabs="https://www.layui.com/doc/element/timeline.html">
<span>时间线 </span>
<span class="layui-font-12 layui-font-gray">timeline</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="auxiliar.html" tppabs="https://www.layui.com/doc/element/auxiliar.html">
<span>辅助 </span>
<span class="layui-font-12 layui-font-gray">引用 字段集 横线等</span>
</a>
</div>
</li>
</ul>
</li>
<li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
<div class="layui-menu-body-title">
内置模块
</div>
<hr>
<ul>
<li class="">
<div class="layui-menu-body-title">
<a href="layer.html" tppabs="https://www.layui.com/doc/modules/layer.html">
<span>弹出层 </span>
<span class="layui-font-12 layui-font-gray">layer</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="laydate.html" tppabs="https://www.layui.com/doc/modules/laydate.html">
<span>日期与时间选择 </span>
<span class="layui-font-12 layui-font-gray">laydate</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="laypage.html" tppabs="https://www.layui.com/doc/modules/laypage.html">
<span>分页 </span>
<span class="layui-font-12 layui-font-gray">laypage</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="laytpl.html" tppabs="https://www.layui.com/doc/modules/laytpl.html">
<span>模板引擎 </span>
<span class="layui-font-12 layui-font-gray">laytpl</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="table-1.html" tppabs="https://www.layui.com/doc/modules/table.html">
<span>数据表格 </span>
<span class="layui-font-12 layui-font-gray">table</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="form-1.html" tppabs="https://www.layui.com/doc/modules/form.html">
<span>表单 </span>
<span class="layui-font-12 layui-font-gray">form</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="upload.html" tppabs="https://www.layui.com/doc/modules/upload.html">
<span>文件上传 </span>
<span class="layui-font-12 layui-font-gray">upload</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="dropdown.html" tppabs="https://www.layui.com/doc/modules/dropdown.html">
<span>下拉菜单 </span>
<span class="layui-font-12 layui-font-gray">dropdown</span>
<span class="layui-badge-dot"></span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="transfer.html" tppabs="https://www.layui.com/doc/modules/transfer.html">
<span>穿梭框 </span>
<span class="layui-font-12 layui-font-gray">transfer</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="tree.html" tppabs="https://www.layui.com/doc/modules/tree.html">
<span>树形组件 </span>
<span class="layui-font-12 layui-font-gray">tree</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="colorpicker.html" tppabs="https://www.layui.com/doc/modules/colorpicker.html">
<span>颜色选择器 </span>
<span class="layui-font-12 layui-font-gray">colorpicker</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="element-1.html" tppabs="https://www.layui.com/doc/modules/element.html">
<span>常用元素操作 </span>
<span class="layui-font-12 layui-font-gray">element</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="slider.html" tppabs="https://www.layui.com/doc/modules/slider.html">
<span>滑块 </span>
<span class="layui-font-12 layui-font-gray">slider</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="rate.html" tppabs="https://www.layui.com/doc/modules/rate.html">
<span>评分 </span>
<span class="layui-font-12 layui-font-gray">rate</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="carousel.html" tppabs="https://www.layui.com/doc/modules/carousel.html">
<span>轮播 </span>
<span class="layui-font-12 layui-font-gray">carousel</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="flow.html" tppabs="https://www.layui.com/doc/modules/flow.html">
<span>流加载 </span>
<span class="layui-font-12 layui-font-gray">flow</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="util.html" tppabs="https://www.layui.com/doc/modules/util.html">
<span>工具组件 </span>
<span class="layui-font-12 layui-font-gray">util</span>
</a>
</div>
</li>
<li class="">
<div class="layui-menu-body-title">
<a href="code.html" tppabs="https://www.layui.com/doc/modules/code.html">
<span>代码高亮显示 </span>
<span class="layui-font-12 layui-font-gray">code</span>
</a>
</div>
</li>
</ul>
</li>
</ul>
</div>
<div class="layui-hide-v"> - </div>
</div>
<div class="layui-col-md9 site-content">
<h1 class="site-h1">开始使用 - 声明</h1>
<blockquote class="layui-elem-quote" >
<span style="color:red">因为原官网要下架,使用本js库的网站需要维护,所以copy了一份原官网。本网站只做自己使用,不做任何盈利目的,版权归原layui所有。 </span>
<p style="margin-bottom: 20px; text-align: center">
<img src="logo-2.png" tppabs="https://res.layui.com/static/images/layui/logo-2.png"
style="width: 100%; max-width: 360px;">
</p>
<fieldset class="layui-elem-field layui-field-title site-title">
<legend><a name="compatibility">兼容性和面向场景</a></legend>
</fieldset>
<blockquote class="layui-elem-quote" style="text-align: center;">
layui 兼容人类正在使用的全部浏览器(IE6/7除外),可作为 Web 界面速成开发方案。
</blockquote>
<fieldset class="layui-elem-field layui-field-title site-title">
<legend><a name="get">获得 layui</a></legend>
</fieldset>
<div class="site-text">
<p>1. 官网首页下载</p>
<blockquote class="layui-elem-quote layui-quote-nm">
你可以在我们的 <a
href="javascript:if(confirm('http://www.layui.com/ \n\n���ļ����� Teleport Ultra ����, ��Ϊ ����һ������·���ⲿ������Ϊ������ʼ��ַ�ĵ�ַ�� \n\n�����ڷ������ϴ�����?'))window.location='http://www.layui.com/'"
tppabs="http://www.layui.com/">官网首页</a> 下载到 layui 的最新版,它经过了自动化构建,更适合用于生产环境。目录结构如下:
</blockquote>
<pre class="layui-code">
├─css //css目录
│ │─modules //模块 css 目录(一般如果模块相对较大,我们会单独提取,如下:)
│ │ ├─laydate
│ │ └─layer
│ └─layui.css //核心样式文件
├─font //字体图标目录
└─layui.js //核心库
</pre>
<p>2. Git 仓库下载</p>
<blockquote class="layui-elem-quote layui-quote-nm">
你也可以通过 <a
href="javascript:if(confirm('https://github.com/sentsin/layui/ \n\n���ļ����� Teleport Ultra ����, ��Ϊ ����һ������·���ⲿ������Ϊ������ʼ��ַ�ĵ�ַ�� \n\n�����ڷ������ϴ�����?'))window.location='https://github.com/sentsin/layui/'"
tppabs="https://github.com/sentsin/layui/" target="_blank">GitHub</a> 或 <a
href="javascript:if(confirm('https://gitee.com/sentsin/layui \n\n���ļ����� Teleport Ultra ����, ��Ϊ ����һ������·���ⲿ������Ϊ������ʼ��ַ�ĵ�ַ�� \n\n�����ڷ������ϴ�����?'))window.location='https://gitee.com/sentsin/layui'"
tppabs="https://gitee.com/sentsin/layui" target="_blank">码云</a> 得到 layui 的完整开发包,以便于你进行二次开发,或者 Fork layui
为我们贡献方案
<br><br>
<p>
<iframe src="github-btn.html-user=sentsin&repo=layui&type=watch&count=true&size=large"
tppabs="https://ghbtns.com/github-btn.html?user=sentsin&repo=layui&type=watch&count=true&size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="156px" height="30px"></iframe>
<iframe src="github-btn.html-user=sentsin&repo=layui&type=fork&count=true&size=large"
tppabs="https://ghbtns.com/github-btn.html?user=sentsin&repo=layui&type=fork&count=true&size=large"
allowtransparency="true" frameborder="0" scrolling="0" width="156px" height="30px"></iframe>
</p>
<div class="layui-btn-container">
<a class="layui-btn layui-btn-normal"
href="javascript:if(confirm('https://github.com/sentsin/layui/ \n\n���ļ����� Teleport Ultra ����, ��Ϊ ����һ������·���ⲿ������Ϊ������ʼ��ַ�ĵ�ַ�� \n\n�����ڷ������ϴ�����?'))window.location='https://github.com/sentsin/layui/'"
tppabs="https://github.com/sentsin/layui/" target="_blank" rel="nofollow"
style="background-color: #24292E; color: #fff;">GitHub</a>
<a class="layui-btn layui-btn-normal"
href="javascript:if(confirm('https://gitee.com/sentsin/layui/ \n\n���ļ����� Teleport Ultra ����, ��Ϊ ����һ������·���ⲿ������Ϊ������ʼ��ַ�ĵ�ַ�� \n\n�����ڷ������ϴ�����?'))window.location='https://gitee.com/sentsin/layui/'"
tppabs="https://gitee.com/sentsin/layui/" target="_blank" rel="nofollow"
style="background-color: #C71D23; color: #fff;">码云</a>
</div>
</blockquote>
<p>3. npm 下载</p>
<pre class="layui-code" lay-skin="notepad">
npm i layui
</pre>
<br>
<p>4. 第三方 CDN 方式引入:</p>
<div class="layui-btn-container">
<a class="layui-btn layui-btn-primary layui-border-black"
href="javascript:if(confirm('https://unpkg.com/browse/layui/dist/ \n\n���ļ����� Teleport Ultra ����, ��Ϊ ����һ������·���ⲿ������Ϊ������ʼ��ַ�ĵ�ַ�� \n\n�����ڷ������ϴ�����?'))window.location='https://unpkg.com/browse/layui/dist/'"
tppabs="https://unpkg.com/browse/layui/dist/" target="_blank" rel="nofollow">UNPKG</a>
<a class="layui-btn layui-btn-primary" style="border-color: #E64E3D; color: #E64E3D;"
href="javascript:if(confirm('https://cdnjs.com/libraries/layui \n\n���ļ����� Teleport Ultra ����, ��Ϊ ����һ������·���ⲿ������Ϊ������ʼ��ַ�ĵ�ַ�� \n\n�����ڷ������ϴ�����?'))window.location='https://cdnjs.com/libraries/layui'"
tppabs="https://cdnjs.com/libraries/layui" target="_blank" rel="nofollow">CDNJS</a>
</div>
<blockquote class="layui-elem-quote layui-text">
UNPKG 和 CDNJS 均为第三方开源免费的 CDN,通过 NPM/GitHub 实时同步。另外还有 <a
href="javascript:if(confirm('https://www.layuicdn.com/ \n\n���ļ����� Teleport Ultra ����, ��Ϊ ����һ������·���ⲿ������Ϊ������ʼ��ַ�ĵ�ַ�� \n\n�����ڷ������ϴ�����?'))window.location='https://www.layuicdn.com/#Layui'"
tppabs="https://www.layuicdn.com/#Layui" target="_blank" rel="nofollow">LayuiCDN</a>。
</blockquote>
<pre class="layui-code" lay-title="UNPKG 引入示例">
<!-- 引入 layui.css -->
<link rel="stylesheet" href="//unpkg.com/layui@<span class="site-showv"></span>/dist/css/layui.css">
<!-- 引入 layui.js -->
<script src="//unpkg.com/layui@<span class="site-showv"></span>/dist/layui.js">
</pre>
</div>
<fieldset class="layui-elem-field layui-field-title site-title">
<legend><a name="quickstart">快速上手</a></legend>
</fieldset>
<div class="site-text">
<p>如果你将 layui 下载到了本地,那么可将其完整地放置到你的项目目录(或静态资源服务器),这是一个基本的入门页面:</p>
<pre class="layui-code" lay-lang="HTML">
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>开始使用 layui</title>
<link rel="stylesheet" href="./layui/css/layui.css">
</head>
<body>
<!-- 你的 HTML 代码 -->
<script src="./layui/layui.js"></script>
<script>
layui.use(['layer', 'form'], function(){
var layer = layui.layer
,form = layui.form;
layer.msg('Hello World');
});
</script>
</body>
</html>
</pre>
</div>
<fieldset class="layui-elem-field layui-field-title site-title">
<legend><a name="classical">经典,因返璞归真</a></legend>
</fieldset>
<div class="site-text">
<p>layui 定义为「经典模块化」,并非是自吹她自身有多优秀,而是有意避开当下 JS
社区的主流方案,试图以尽可能简单的方式去诠释高效!<em>她的所谓经典,是在于对返璞归真的执念</em>,她以当前浏览器普通认可的方式去组织模块!我们认为,这恰是符合当下国内绝大多数程序员从旧时代过渡到未来新标准的绝佳指引。所以
layui 本身也并不是完全遵循于 AMD 时代,准确地说,她试图建立自己的模式:</p>
<pre class="layui-code">
//layui 模块的定义(新 js 文件)
layui.define([mods], function(exports){
//……
exports('mod', api);
});
//layui 模块的使用
layui.use(['mod1', 'mod2'], function(args){
var mod = layui.mod1;
//……
});
</pre>
<p>没错,她具备早前 AMD 的影子,又并非受限于 CommonJS 的那些条条框框,layui
认为这种轻量的组织方式,比WebPack更符合绝大多数场景。所以她坚持采用经典模块化,也正是能让人避开工具的复杂配置,回归简单,安静高效地编织原生态的 HTML/CSS/JS。</p>
<p>但是 layui 又并非是 RequireJS 那样的模块加载器,而是一款 UI 解决方案,与 BootStrap 的不同又在于:layui 糅合了自身对经典模块化的理解。这使得你可以在 layui
组织的框架之内,以更具可维护性的代码、去更好的编织丰富的用户界面。</p>
</div>
<fieldset class="layui-elem-field layui-field-title site-title">
<legend><a name="modules">建立模块入口</a></legend>
</fieldset>
<div class="site-text">
<p>您可以遵循 layui 的模块规范建立一个入口文件,并通过 layui.use() 方式来加载该入口文件,如下所示:</p>
<pre class="layui-code">
<!-- 你引入的 layui.js 建议是通过官网首页下载的。当然也可以由 github 或 gitee clone -->
<script src="./layui/layui.js"></script>
<script>
layui.config({
base: '/res/js/modules/' //你存放新模块的目录,注意,不是 layui 的模块目录
}).use('index'); //加载入口
</script>
</pre>
上述的 index 即为你 /res/js/modules/ 目录下的 index.js,它的内容应该如下:
<pre class="layui-code">
/**
index.js 项目 JS 主入口
以依赖 layui 的 layer 和 form 模块为例
**/
layui.define(['layer', 'form'], function(exports){
var layer = layui.layer
,form = layui.form;
layer.msg('Hello World');
exports('index', {}); //注意,这里是模块输出的核心,模块名必须和 use 时的模块名一致
});
</pre>
<p>
<span class="layui-font-red">从 layui 2.6 开始</span>,如果你引入的是构建后的 <code>layui.js</code>,里面即包含了 layui
所有的内置模块,无需再指定内置模块。如:
</p>
<pre class="layui-code">
/**
index.js 项目 JS 主入口
**/
layui.define(function(){ // 需确保您的 layui.js 是引入的构建后的版本(即官网下载或 git 平台的发行版)
//直接可得到各种内置模块
var layer = layui.layer
,form = layui.form
,table = layui.table;
//…
layer.msg('Hello World');
exports('index', {}); //注意,这里是模块输出的核心,模块名必须和 use 时的模块名一致
});
</pre>
</div>
<fieldset class="layui-elem-field layui-field-title site-title">
<legend><a name="extmodules">管理扩展模块</a></legend>
</fieldset>
<div class="site-text">
<p>
除了使用 layui 的内置模块,必不可少也需要加载扩展模块(可以简单理解为符合 layui 模块规范的 JS 文件)。我们假设你的项目中存放了很多个扩展模块,如下所举:</p>
<pre class="layui-code">
//mod1.js
layui.define('layer', function(exports){
//…
exports(mod1, {});
});
//mod2.js,假设依赖 mod1 和 form
layui.define(['mod1', 'form'], function(exports){
//…
exports(mod2, {});
});
//mod3.js
//…
//main.js 主入口模块
layui.define('mod2', function(exports){
//…
exports('main', {});
});
</pre>
<p>上述扩展模块在经过了一定的模块依赖关系后,同样可以合并为一个文件来加载。我们可以借助 Gulp 将上述的 <code>mod1、mod2、mod3、main</code>
等扩展模块构建合并到一个模块文件中:<code>main.js</code>,此时你只需要加载它即可:</p>
<pre class="layui-code">
<script src="./layui/layui.js"></script>
<script>
layui.config({
base: '/res/js/modules/' //你的扩展模块所在目录
}).use('main'); //这里的 main 模块包含了 mod1、mod2、mod3 等等扩展模块
</script>
</pre>
<p>可以看到,这样我们最多只需要加载两个 JS 文件:<code>layui.js、main.js</code>。这将大幅度减少静态资源的请求。</p>
<blockquote class="layui-elem-quote layui-quote-nm layui-text" style="margin-top: 20px;">
通过上面的阅读,也许你已大致了解如何使用 layui 了,不过你可能还需要继续阅读后面的文档,尤其是「基础说明」。
<br>那么,欢迎你开始拥抱 layui!愿它能成为你得心应手的 Web 界面解决方案,化作你方寸屏幕前的亿万字节!
</blockquote>
</div>
<div class="layui-elem-quote">
<p>layui - 在每一个细节中,用心与你沟通</p>
</div>
</div>
</div>
<div class="layui-footer footer footer-doc">
<p>致敬layui</p>
</div>
<script>
window.global = {
pageType: 'doc'
, preview: function () {
var preview = document.getElementById('LAY_preview');
return preview ? preview.innerHTML : '';
}()
};
</script>
<script src="https://cdn.bootcdn.net/ajax/libs/layui/2.6.8/layui.js"></script>
<div class="site-tree-mobile layui-hide">
<i class="layui-icon layui-icon-spread-left"></i>
</div>
<div class="site-mobile-shade"></div>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。