vue3【组件封装】确认对话框 Modal

src/components/Modal.vue

html 复制代码
<template>
  <transition name="fade">
    <div
      class="fixed w-full h-full z-100 top-0 left-0 bg-black bg-opacity-30 flex transition-all"
      v-if="show"
    >
      <div class="w-80 m-auto bg-white border shadow-lg rounded-2 px-4 py-6">
        <slot></slot>
        <div class="flex justify-end pt-4">
          <div class="btn-plain px-6 mr-4" @click="show = false">取消</div>
          <div
            class="btn px-6"
            @click="
              () => {
                show = false
                $emit('confirm')
              }
            "
          >
            确定
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script setup lang="ts">
defineEmits(['confirm'])
const show = defineModel({ default: false })
</script>

使用

html 复制代码
  <button @click="show_confirmWin = true">删除</button>

  <teleport to="body">
    <Modal v-model="show_confirmWin" @confirm="del"> 确定删除吗? </Modal>
  </teleport>
ts 复制代码
const show_confirmWin = ref(false)
const del = () => {
  alert('删除成功!')
}
相关推荐
小云小白8 天前
高性能 v-html 弹窗实现:Vue3 + Element Plus 最佳实践
vue3·弹窗·v-html
xun-ming9 天前
SpringBoot和Vue3实战阿里百炼大模型极简版
spring boot·ai·vue3·智能体·百炼大模型
哆啦A梦15889 天前
20, Springboot3+vue3实现前台轮播图和详情页的设计
javascript·数据库·spring boot·mybatis·vue3
小盼江9 天前
基于Springboot3+Vue3的协同过滤鲜花商城推荐系统
vue3·springboot3·鲜花商城
哆啦A梦158810 天前
11,Springboot3+vue3个人中心,修改密码
java·前端·javascript·数据库·vue3
哆啦A梦158811 天前
01, 前端vue3框架的快速搭建以及项目工程的讲解
前端·vue3·springboot
萧曵 丶15 天前
Vue3组件通信全方案
前端·javascript·vue.js·typescript·vue3
Json____15 天前
vue3-商城管理系统-前端静态网站
前端·vue3·ts·商城纯静态
吴声子夜歌20 天前
Vue3——网络框架Axios的应用
javascript·vue3·axios
赵庆明老师1 个月前
vben开发入门6:tsconfig.json
json·vue3·vben