Appearance
NwModal弹框组件
基础用法
展开查看
vue
<template>
<div class="example">
<Button type="primary" @click="handleModal1">打开弹框</Button>
<NwModal v-model:visible="visiable" title="弹框1">
<div ref="divRef" style="width: 100%; height: 200px">
国外的信号塔就是不一样,
上面竟然还写着汉字
</div>
</NwModal>
</div>
</template>
<script setup lang="ts">
import {ref} from 'vue'
import { NwModal } from '@nw-design/ui'
import {Button} from 'ant-design-vue'
import '@nw-design/ui/dist/es/style.css'
const visiable = ref(false)
const handleModal1 = () => {
visiable.value =true
}
</script>
可拖拽可全屏
展开查看
vue
<template>
<div class="example">
<Button type="primary" @click="handleModal2">打开弹框2</Button>
<NwModal v-model:visible="visiable2" title="可拖拽可全屏弹框" :draggable="true" :canFullscreen="true">
<div ref="divRef" style="width: 100%; height: 200px">
我爱世界杯 享受比赛
</div>
</NwModal>
</div>
</template>
<script setup lang="ts">
import {ref} from 'vue'
import { NwModal } from '@nw-design/ui'
import {Button} from 'ant-design-vue'
import '@nw-design/ui/dist/es/style.css'
const visiable2 = ref(false)
const handleModal2 = () => {
visiable2.value =true
}
</script>
自定义底部按钮
展开查看
vue
<template>
<div class="example">
<Button type="primary" @click="handleModal3">打开弹框3</Button>
<NwModal v-model:visible="visiable3" title="自定义底部按钮弹框" :confirmLoading="true">
<div ref="divRef" style="width: 100%; height: 200px">
喜羊羊,美羊羊,懒羊羊,暖羊羊,沸羊羊,慢羊羊,红太狼,灰太狼,别看我只是一只羊
</div>
<template #insertFooter>
<Button type="primary" danger>一键去阳</Button>
</template>
</NwModal>
</div>
</template>
<script setup lang="ts">
import {ref} from 'vue'
import { NwModal } from '@nw-design/ui'
import {Button} from 'ant-design-vue'
import '@nw-design/ui/dist/es/style.css'
const visiable3 = ref(false)
const handleModal3 = () => {
visiable3.value =true
}
</script>
API
通过设置NwModal的属性可以实现不同的效果。 弹框组件的属性说明如下:
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| visible(v-model) | 对话框是否可见 | boolean | false |
| draggable | 是否可以拖动 | boolean | false |
| canFullscreen | 是否可以全屏 | boolean | false |
| defaultFullscreen | 是否全屏显示 | boolean | false |
| showOkBtn | 是否展示确认按钮 | boolean | true |
| showCancelBtn | 是否展示取消按钮 | boolean | true |
| afterClose | Modal 完全关闭后的回调 | function | 无 |
| bodyStyle | Modal body 样式 | object | {} |
| cancelText | 取消按钮文字 | string | 取消 |
| closable | M是否显示右上角的关闭按钮 | boolean | true |
| confirmLoading | 确定按钮 loading | boolean | 无 |
| destroyOnClose | 关闭时销毁 Modal 里的子元素 | boolean | false |
| footer | 底部内容,当不需要默认底部按钮时,可以设为 :footer="null" | string | slot |
| mask | 是否展示遮罩 | boolean | true |
| maskClosable | 点击蒙层是否允许关闭 | boolean | true |
| maskStyle | 遮罩样式 | object | {} |
| okText | 确认按钮文字 | string | 确定 |
| okType | 确认按钮类型 | string | primary |
| okButtonProps | ok 按钮 props | ButtonProps | - |
| cancelButtonProps | cancel 按钮 props | ButtonProps | - |
| title | 标题 | string | slot |
| width | 宽度 | string | number |
| zIndex | 设置 Modal 的 z-index | number | 1000 |
事件
| 事件名称 | 说明 | 参数 |
|---|---|---|
| cancel | 点击遮罩层或右上角叉或取消按钮的回调 | function(e) |
| ok | 点击确定回调 | function(e) |