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('删除成功!')
}
相关推荐
Modify_QmQ2 天前
leaflet【十一】地图瓦片路径可视化
gis·vue3·leaflet·leafletmapblock
ldj202013 天前
vue3整合element-plus
vue3
夜空孤狼啸18 天前
前端常用拖拽组件库(vue3、react、vue2)
前端·javascript·react.js·typescript·前端框架·vue3
sunshine_程序媛18 天前
vue3中的watch和watchEffect区别以及demo示例
前端·javascript·vue.js·vue3
meng半颗糖19 天前
vue3 双容器自动扩展布局 根据 内容的多少 动态定义宽度
前端·javascript·css·vue.js·elementui·vue3
3D虚拟工厂20 天前
3D虚拟工厂
3d·vue3·blender·数字孪生·three.js
霸王蟹23 天前
前端项目Excel数据导出同时出现中英文表头错乱情况解决方案。
笔记·学习·typescript·excel·vue3·react·vite
佚名猫1 个月前
vue3+vite+pnpm项目 使用monaco-editor常见问题
前端·vue3·vite·monacoeditor
技术闲聊DD1 个月前
Vue3学习(4)- computed的使用
vue3·computed
蓝胖子的多啦A梦1 个月前
Vue3 (数组push数据报错) 解决Cannot read property ‘push‘ of null报错问题
前端·vue3·push·数组数据