Skip to content

信息提示 Modal


模态对话框

何时使用

  • 在当前页面正中打开一个浮层,承载相应的操作或者提示内容

confirm

Show Code
vue
<script setup lang="ts">
import { ref } from 'vue'

const modal = ref()
const loading = ref(false)
const visible = ref(false)
function showConfirmModal (content: string) {
  modal.value.confirm({
    title: 'Do you Want to submit these items ?',
    content: content
  })
  visible.value = true
}
function onCancel () { // “取消”按钮回调
  visible.value = false
}
function onConfirm () { // “确定”按钮回调
  loading.value = true // 开启加载状态
  setTimeout(() => {
    visible.value = false
    loading.value = false
  }, 500)
}
</script>
<template>
  <Button type="primary" @click="showConfirmModal('Some descriptions ...')">Confirm</Button>
  <Modal
    ref="modal"
    :loading="loading"
    :visible="visible"
    @cancel="onCancel"
    @ok="onConfirm" />
</template>

erase

Show Code
vue
<script setup lang="ts">
import { ref } from 'vue'

const modal = ref()
const loading = ref(false)
const visible = ref(false)
function showEraseModal (content: string) {
  modal.value.erase({
    title: 'Do you Want to delete these items ?',
    content: content
  })
  visible.value = true
}
function onCancel () { // “取消”按钮回调
  visible.value = false
}
function onConfirm () { // “确定”按钮回调
  loading.value = true // 开启加载状态
  setTimeout(() => {
    visible.value = false
    loading.value = false
  }, 500)
}
</script>
<template>
  <Button type="primary" @click="showEraseModal('Some descriptions ...')">Erase</Button>
  <Modal
    ref="modal"
    :loading="loading"
    :visible="visible"
    @cancel="onCancel"
    @ok="onConfirm" />
</template>

info

Show Code
vue
<script setup lang="ts">
import { ref } from 'vue'

const modal = ref()
const visible = ref(false)
function showInfoModal (content: string) {
  modal.value.info({
    title: 'Do you See these items ?',
    content: content
  })
  visible.value = true
}
function onKnow () { // “我知道了”按钮回调
  visible.value = false
}
</script>
<template>
  <Button type="primary" @click="showInfoModal('Some descriptions ...')">Info</Button>
  <Modal
    ref="modal"
    :visible="visible"
    @know="onKnow" />
</template>

success

Show Code
vue
<script setup lang="ts">
import { ref } from 'vue'

const modal = ref()
const visible = ref(false)
function showSuccessModal (content: string) {
  modal.value.success({
    title: 'Do you See these items ?',
    content: content
  })
  visible.value = true
}
function onKnow () { // “我知道了”按钮回调
  visible.value = false
}
</script>
<template>
  <Button type="primary" @click="showSuccessModal('Some descriptions ...')">Success</Button>
  <Modal
    ref="modal"
    :visible="visible"
    @know="onKnow" />
</template>

error

Show Code
vue
<script setup lang="ts">
import { ref } from 'vue'

const modal = ref()
const visible = ref(false)
function showErrorModal (content: string) {
  modal.value.error({
    title: 'Do you See these items ?',
    content: content
  })
  visible.value = true
}
function onKnow () { // “我知道了”按钮回调
  visible.value = false
}
</script>
<template>
  <Button type="primary" @click="showErrorModal('Some descriptions ...')">Error</Button>
  <Modal
    ref="modal"
    :visible="visible"
    @know="onKnow" />
</template>

warning

Show Code
vue
<script setup lang="ts">
import { ref } from 'vue'

const modal = ref()
const visible = ref(false)
function showWarningModal (content: string) {
  modal.value.warning({
    title: 'Do you See these items ?',
    content: content
  })
  center.value = true
  visible.value = true
}
function onKnow () { // “我知道了”按钮回调
  visible.value = false
}
</script>
<template>
  <Button type="primary" @click="showWarningModal('Some descriptions ...')">Warning</Button>
  <Modal
    ref="modal"
    :visible="visible"
    @know="onKnow" />
</template>

高度固定

Show Code
vue
<script setup lang="ts">
import { ref } from 'vue'

const modal = ref()
const visible = ref(false)
function showFixModal (content: string) {
  modal.value.info({
    title: 'Do you See these items ?',
    content: content
  })
  visible.value = true
}
function onKnow () { // “我知道了”按钮回调
  visible.value = false
}
</script>
<template>
  <Button type="primary" @click="showFixModal('Some descriptions ...')">高度固定</Button>
  <Modal
    ref="modal"
    :center="false"
    :top="120"
    :visible="visible"
    @know="onKnow" />
</template>

APIs

参数说明类型默认值必传
width提示框宽度,单位pxnumber420false
cancelText取消按钮文字string'取消'false
okText确认按钮文字string'确定'false
noticeText通知按钮文字string'知道了'false
centertrue: 水平垂直居中;false: 固定高度水平居中booleantruefalse
top固定高度水平居中时,距顶部高度,单位pxnumber100false
loading加载中booleanfalsefalse
visible是否可见booleanfalsefalse

Events

事件名称说明参数
cancel点击遮罩层或取消按钮的回调() => void
ok点击确定回调() => void
know点击知道了的回调() => void

Released under the MIT License.