Files
layui/package/document-layer/src/document/zh-CN/demo.md
0o张不歪o0 21835edb61 🐛(component): 尝试解决layer.open 内容自适应
ISSUES CLOSED: #I5E4OM
2022-06-28 10:58:18 +08:00

9.9 KiB

消息

::: demo 通过 layer.msg(content, options) 创建消息窗, 第一个参数msg为消息内容, 第二参数options为可选配置, 常用于配置time超时时间等。

普通消息 成功消息 失败消息 警告消息 锁定消息 <script> import { layer } from "../../../../layer/src/index" const msg = function() { layer.msg("普通消息", { time: 1000 }) } const success = function() { layer.msg("成功消息", { time: 1000, icon: 1}) } const failure = function() { layer.msg("失败消息", { time: 1000, icon: 2}) } const warm = function() { layer.msg("警告消息", { time: 1000, icon: 3}) } const info = function() { layer.msg("疑问消息", { time: 1000, icon: 4}) } </script>

:::

确认

::: demo 通过 layer.confirm(msg, options) 创建确认框, 第一个参数msg为文本消息, 第二个参数options为选项配置, 你可以使用optionsbtn属性定义操作。

确认框 询问框 <script setup> import { layer } from "../../../../layer/src/index" const openConfirm1 = function() { layer.confirm("layui-vue 1.0.0 已经发布") } const openConfirm2 = function() { layer.confirm("你如何看待 layui-vue 的发布", {btn: [ {text:'站着看', callback: function(id){layer.close(id);}}, {text:'坐着看', callback: function(id){layer.close(id);}} ] }) } </script>

:::

加载

::: demo 通过 layer.load(type, options) 创建加载层, 第一个参数type为加载动画样式, 第二个参数options为可选配置, 常用于设置time加载时长shade遮盖层等。

加载1 加载2 加载3 加载4 <script setup> import { layer } from "../../../../layer/src/index" const load1 = function() { layer.load(0, {time: 2000}) } const load2 = function() { layer.load(1, {time: 2000}) } const load3 = function() { layer.load(2, {time: 2000}) } const load4 = function() { layer.msg("加载中...",{icon: 16, time: 2000}) } </script>

:::

模态

::: demo 通过 layer.open(option) 创建模态窗, 目前支持iframe page等类型, 你可以使用options选项开启Resize Offset等更多特性。

小试牛刀 指定尺寸 指定位置 远程窗体 代码片段 虚拟节点 缩小放大 尺寸拉伸 设置层级 内容适应 内容适应2 <script setup> import { layer } from "../../../../layer/src/index" const open = function() { layer.open({ type: 1, title: "标题", content: "内容" }) } const openSize = function() { layer.open({ type: 1, title: "标题", area: ['400px','400px'], content: "内容" }) } const openOffset = function() { layer.open({ type: 1, title: "标题", offset: ['100px','100px'], content: "内容" }) } const openIframe = function() { layer.open({ type: 2, title: "标题", resize: true, area: ['500px','500px'], content: "http://layui-vue.pearadmin.com" }) } const openHtml = function() { layer.open({ type: 1, title: "标题", isHtmlFragment: true, content: "

内容

" }) } const openVNode = function() { layer.open({ type: 1, title: "标题", content: h('button', { style: 'margin: 10px;' },'按钮') }) } const openMaxmin = function() { layer.open({ type: 1, title: "标题", maxmin: true, content: "内容" }) } const openResize = function() { layer.open({ type: 1, title: "标题", resize: true, content: "内容" }) } const openIndex = function() { layer.open({ type: 1, title: "标题", zIndex: 999, content: "设置层级" }) } const openAreaAuto = function(){ layer.open({ type:1, title:"area:auto", isHtmlFragment:true, content:"" }) } const openAreaAuto2 = function(){ layer.open({ type:1, title:"area:auto", offset:['10px','50%'], isHtmlFragment:true, content:"" }) } </script>

:::

抽屉

::: demo 通过 layer.drawer(options) 创建抽屉层, options选项配置, 抽屉本质上是一个特殊的模态窗, 你可以使用offset选项来设置方向。 <button @click="openTop">上 <button @click="openBottom">下 <button @click="openLeft">左 <button @click="openRight">右

<script setup> import { layer } from "../../../../layer/src/index" const openTop = function() { layer.drawer({ title: "标题", content: "内容", offset: "t" }) } const openBottom = function() { layer.drawer({ title: "标题", content: "内容", offset: "b" }) } const openLeft = function() { layer.drawer({ title: "标题", content: "内容", offset: "l" }) } const openRight = function() { layer.drawer({ title: "标题", content: "内容", offset: "r" }) } </script>

:::

图片

::: demo 通过 layer.photos(options) 创建图片预览弹层, 参数options主要传入预览的图片链接。

图片查看 图片标题 图片分组 <script> import { layer } from "../../../../layer/src/index" const signleImg = function() { layer.photos("/src/assets/logo.jpg") } const signleImg2 = function() { layer.photos({ imgList:[{src:'/src/assets/logo.jpg',alt:'layer for vue'}] }) } const groupImg = function() { layer.photos({ imgList:[ { src:'http://www.pearadmin.com/assets/images/un8.svg', alt:'图片1'}, { src:'http://www.pearadmin.com/assets/images/un32.svg', alt:'图片2'} ] }) } </script>

:::

销毁

::: demo 我们提供 layer.close(id) 与 layer.closeAll() 函数实现弹出层的主动销毁。

打开 销毁 销毁全部 <script setup> import { layer } from "../../../../layer/src/index"; let id = null; const open = function() { id = layer.open({ title: "标题", content: "内容", shade: false }) } const close = function() { layer.close(id); } const closeAll = function() { layer.closeAll(); } </script>

:::

通讯

::: demo 👉 查看 Children1.vue, 通过 h() 函数的第二个参数向 Children1.vue 传递响应式变量。

数据 <script setup> import { reactive, h, resolveComponent } from 'vue' import { layer } from "../../../../layer/src/index" const data = reactive({ remark: "信息" }) const ChildrenOne = resolveComponent('Children1') const openComponent1 = () => { layer.open({ title: '标题', content: h(ChildrenOne, { data }), shade: false, }) } </script>

:::

::: demo 👉 查看 Children2.vue, 通过 h() 函数的第二个参数声明 onXxx() 形式的函数完成 Children2.vue 的事件监听。

事件 <script setup> import { reactive, h, resolveComponent, ref } from 'vue' import { layer } from "../../../../layer/src/index" const prop = reactive({}) const numb = ref(1000) const ChildrenTwo = resolveComponent('Children2') const openComponent2 = () => { layer.open({ title: '标题', content: h(ChildrenTwo, { prop, onAdd(res){ numb.value = numb.value + 1; }, onSub(res) { numb.value = numb.value - 1; } }), }) } </script>

:::