- 🎯 命令式调用 - 通过函数调用控制组件,而非模板声明
- 🔥 简化代码 - 减少繁杂的模板代码和状态管理
- 🎨 多UI库支持 - 已适配 Element Plus、Naive UI、Vant
- 📦 开箱即用 - 零配置,安装即用
- 🔧 完整的环境信息 - 保留完整的Vue环境上下文
- 🚀 Promise支持 - 优雅的异步流程处理
- 💪 TypeScript支持 - 完整的类型定义
<template>
<div>
<el-button @click="showDialog = true">打开弹窗</el-button>
<!-- 需要在模板中定义弹窗 -->
<el-dialog
v-model="showDialog"
title="用户信息"
@confirm="handleConfirm"
@cancel="handleCancel"
>
<UserForm :user="currentUser" @submit="handleSubmit" />
</el-dialog>
</div>
</template>
<script setup>
import { ref } from "vue";
// 需要管理状态
const showDialog = ref(false);
const currentUser = ref(null);
// 需要多个事件处理函数
const handleConfirm = () => {
showDialog.value = false;
};
const handleCancel = () => {
showDialog.value = false;
};
const handleSubmit = (userData) => {
// 处理提交逻辑
showDialog.value = false;
};
</script><template>
<div>
<el-button @click="openUserDialog">打开弹窗</el-button>
</div>
</template>
<script setup>
import { useDialog } from "@vue-cmd/element-plus";
const dialog = useDialog();
const openUserDialog = async () => {
try {
const userData = await dialog(<UserForm user={currentUser} />, {
title: "用户信息",
}).promise;
// 直接获取结果,无需额外状态管理
console.log("用户数据:", userData);
} catch (error) {
console.log("用户取消了操作");
}
};
</script>对比结果:代码量减少极大,无需状态管理,逻辑更清晰!
# 选择你使用的UI库
npm install @vue-cmd/element-plus # Element Plus
npm install @vue-cmd/naive # Naive UI
npm install @vue-cmd/vant # Vantimport { useDialog } from "@vue-cmd/element-plus";
const dialog = useDialog();
// 简单调用
dialog(<div>Hello World!</div>);
// 带配置
dialog(<UserForm />, {
title: "编辑用户",
width: "500px",
});const result = await dialog(<UserForm />, {
title: "新增用户",
}).promise;
console.log("用户提交的数据:", result);const openNestedDialogs = async () => {
const step1 = await dialog(<Step1 />).promise;
const step2 = await dialog(<Step2 data={step1} />).promise;
const step3 = await dialog(<Step3 data={step2} />).promise;
console.log("完成所有步骤:", step3);
};- ✅ 弹窗类组件:Dialog、Modal、Drawer
- ✅ 确认类交互:删除确认、操作确认
- ✅ 表单编辑:行内编辑、快速编辑
- ✅ 多步骤流程:向导、分步表单
- ✅ 临时性UI:提示框、通知
| UI库 | 包名 | 状态 |
|---|---|---|
| Element Plus | @vue-cmd/element-plus |
✅ 已支持 |
| Naive UI | @vue-cmd/naive |
✅ 已支持 |
| Vant | @vue-cmd/vant |
✅ 已支持 |
| Ant Design Vue | - | 🚧 计划中 |
| Quasar | - | 🚧 计划中 |
欢迎贡献代码!请查看 贡献指南。
MIT © 2024