Vue3之弹窗

Vue3之弹窗


在前端开发语言Vue3,在管理端如何进行弹窗?下面根据API实现效果。
Element API文档: Element-plus文档

搭建环境可参考博客【 初探Vue3环境搭建与nvm使用】

第一步、引入JS

<script lang="ts" setup>
import { ref } from 'vue'
import { ElMessageBox } from 'element-plus'
// 设置变量
const dialogVisible = ref(false)
// 
const handleClose = (done: () => void) => {
  ElMessageBox.confirm('是否关闭弹窗')
    .then(() => {
      done()
    })
    .catch(() => {
      // 异常处理 
    })
}
</script>

第二步、弹框

添加按钮事件

<template>
  <el-button plain @click="dialogVisible = true">
    点击弹窗
  </el-button>

  <el-dialog
    v-model="dialogVisible"
    title="弹窗"
    width="500"
    :before-close="handleClose"
  >
    <span>This is a message</span>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogVisible = false">Cancel</el-button>
        <el-button type="primary" @click="dialogVisible = false">
          确认
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>
转载请说明出处内容投诉
CSS教程网 » Vue3之弹窗

发表评论

欢迎 访客 发表评论

一个令你着迷的主题!

查看演示 官网购买