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('删除成功!')
}
相关推荐
我是ed.1 天前
Vue3 图片标注插件 AILabel
前端·vue3·标注·ailabel
熊猫钓鱼>_>2 天前
Vue3 + Tailwind CSS + DaisyUI 现代前端开发完全攻略
前端·css·vue.js·vue3·tailwind·daisyui·现代开发
小白_ysf2 天前
Vue3+TS项目中高德地图组件封装(集成关键词搜索、输入提示、标记点、信息弹窗和数据回显)
vue3·ts·高德·地图 js api
Light603 天前
Vue 高阶优化术:v-bind 与 v-on 的实战妙用与思维跃迁
前端·低代码·vue3·v-bind·组件封装·v-on·ai辅助开发
Jeking2177 天前
进阶流程图绘制工具 Unione Flow Editor-- 巧用Event事件机制,破解复杂业务交互难题
流程图·vue3·workflow·unione flow·flow editor·unione cloud
一只小阿乐8 天前
前端vue3 web端中实现拖拽功能实现列表排序
前端·vue.js·elementui·vue3·前端拖拽
AAA阿giao8 天前
从“操纵绳子“到“指挥木偶“:Vue3 Composition API 如何彻底改变前端开发范式
开发语言·前端·javascript·vue.js·前端框架·vue3·compositionapi
૮・ﻌ・8 天前
Vue3:组合式API、Vue3.3新特性、Pinia
前端·javascript·vue3
凯小默11 天前
37-实现地图配置项(完结)
echarts·vue3
凯小默12 天前
36-引入地图
echarts·vue3