Skip to content

r-dialog

r-dialog 弹出框,弹出模态框,常用于消息提示、消息确认,或在当前页面内完成特定的交互操作。

示例

vue
<template>
  <r-config-provider>
    <view style="padding: 20px 0">
      <r-divider content-position="left">基础使用</r-divider>
      <r-cell-group inset>
        <r-cell title="提示弹窗" isLink @click="open(1)"></r-cell>
        <r-cell title="提示弹窗(无标题)" isLink @click="open(2)"></r-cell>
        <r-cell title="确认弹窗" isLink @click="open(3)"></r-cell>
      </r-cell-group>

      <r-divider content-position="left">异步关闭</r-divider>
      <r-cell-group inset>
        <r-cell title="异步关闭" isLink @click="open2()"></r-cell>
      </r-cell-group>

      <r-divider content-position="left">自定义内容</r-divider>
      <r-cell-group inset>
        <r-cell title="自定义内容" isLink @click="show3 = true"></r-cell>
      </r-cell-group>
    </view>
  </r-config-provider>
  <r-dialog
    v-model:show="show"
    :title="title"
    closeOnClickOverlay
    message="message"
    :showCancelButton="showCancelButton"
  ></r-dialog>

  <r-dialog
    v-model:show="show2"
    title="title"
    message="message"
    showCancelButton
    :beforeClose="beforeClose"
  ></r-dialog>

  <r-dialog
    v-model:show="show3"
    title="title"
    message="message"
    showCancelButton
  >
    <view style="width: 100%; padding: 10px; box-sizing: border-box">
      <r-image
        width="346px"
        src="https://fastly.jsdelivr.net/npm/@vant/assets/apple-3.jpeg"
      ></r-image>
    </view>
  </r-dialog>
</template>

<script setup>
import { ref } from "vue";
const show = ref(false);
const show2 = ref(false);
const show3 = ref(false);
const title = ref("");
const showCancelButton = ref(false);
const open = (type) => {
  title.value = "";
  showCancelButton.value = false;
  if (type == 1) {
    title.value = "提示弹窗";
  }
  if (type == 3) {
    title.value = "确认弹窗";
    showCancelButton.value = true;
  }
  show.value = true;
};
const beforeClose = (action) =>
  new Promise((resolve) => {
    setTimeout(() => {
      // action !== 'confirm'  拦截取消操作
      resolve(action === "confirm");
    }, 1000);
  });
const open2 = () => {
  show2.value = true;
};
</script>

API

Props

名称说明类型默认值可选值
show是否显示弹窗Booleanfalsetrue
title标题String--
width弹窗宽度String320px
message文本内容String--
messageAlign内容水平对齐方式Stringcenterleft right justify
showConfirmButton是否展示确认按钮Booleantruefalse
showCancelButton是否展示取消按钮Booleanfalsetrue
confirmButtonText确认按钮文案String确认
confirmButtonColor确认按钮颜色String#1989fa
confirmButtonDisabled是否禁用确认按钮Booleanfalsetrue
cancelButtonText取消按钮文案String取消
cancelButtonColor取消按钮颜色Stringblack
cancelButtonDisabled是否禁用取消按钮Booleanfalsetrue
zIndex将弹窗的 z-index 层级设置为一个固定值Number2000
overlay是否展示遮罩层Booleantruefalse
overlayClass自定义遮罩层类名String-
overlayStyle自定义遮罩层样式Object{}
closeOnClickOverlay是否在点击遮罩层后关闭弹窗Booleanfalsetrue
lockScroll是否锁定背景滚动Booleantruefalse
beforeClose关闭前的回调函数,返回 false 可阻止关闭,支持返回 PromiseFunction-
themeNamer-theme主题名称Stringdefault

Events

名称说明参数
confirm点击确认按钮时触发-
cancel点击取消按钮时触发-
open打开弹窗时触发-
close关闭弹窗时触发-
opened打开弹窗且动画结束后触发-
closed关闭弹窗且动画结束后触发-
update:value显示状态变化时触发show

Slots

名称说明参数
default自定义内容-
title自定义标题-
footer自定义底部按钮区域-

更多组件,请前往rainui