element-plus组件中的el-drawer的使用

在项目的制作过程中经常会用到弹窗组件,这里假设一种情况当你在一个页面需要多个弹窗组件的时候怎么样才能精准的打开和关闭对应的弹窗呐??

① 绑定一个点击事件----【给点击事件传入一个下标】这里是打开事件

② 使用element-plus中的 :before-close点击关闭事件,但是在这里需要传入一个done,所以我的传递方式是这样的

javascript 复制代码
<div>
          <!-- 点击图标显示抽屉组件 -->
          <div :key="1" @click="displayDrawer(1)" style="z-index:6666; position: absolute;left: 46%; top: 5%;">
            <svg-icon width="30px" height="30px" name="zuopinxiangqing"></svg-icon>
          </div>
          <!-- 抽屉组件1 -->
          <el-drawer :key="1" v-model="drawerList[0].display" title="作品详情1" :direction="direction"
             :before-close="(done:any) => handleClose(done, 2)"  :index="1" style="right: 50%;">
            <span>Hi there! This is drawer 1.</span>
          </el-drawer>
        </div>
<div>
            <!-- 点击图标显示抽屉组件 -->
            <div :key="2" @click="displayDrawer(2)"
              style="z-index:6666; width: 45px; display: flex; justify-content: flex-end; padding-right: 15px; ">
              <svg-icon width="30px" height="30px" name="zuopinxiangqing"></svg-icon>
            </div>
            <!-- 多个抽屉组件 -->
            <!-- 抽屉组件2 -->
            <el-drawer :key="2" v-model="drawerList[1].display" title="作品详情2" :direction="direction"
            :before-close="(done:any) => handleClose(done, 2)" :index="2">
              <span>Hi there! This is drawer 2.</span>
            </el-drawer>
          </div>

这里有两个弹窗和对应的两个点击事件

javascript 复制代码
<script>
const drawerList = ref([
  { index: 1, title: '作品详情1', display: false },
  { index: 2, title: '作品详情2', display: false }
]);
const displayDrawer = (index: any) => {
  drawerList.value[index - 1].display = true;
};

const handleClose = (done: any, index: any) => {
  drawerList.value[index - 1].display = false;
  done()
};
</script>

这里的

javascript 复制代码
:before-close="(done:any) => handleClose(done, 2)"

这里我不是很清楚done的状态和类型方法所以使用了上面的方式将数据进行了传递,最终效果。

这里实现了左右两个弹窗!!!

相关推荐
^^为欢几何^^几秒前
npm、pnpm和yarn有什么区别
前端·npm·node.js
前端菜鸟日常7 分钟前
vue2和vue3的按需引入的详细对比通俗易懂
javascript·vue.js·ecmascript
AC-PEACE22 分钟前
Vue 中 MVVM、MVC 和 MVP 模式的区别
前端·vue.js·mvc
播播资源25 分钟前
ChatGPT付费创作系统V3.1.3独立版 WEB端+H5端+小程序端 (DeepSeek高级通道+推理输出格式)安装教程
前端·ai·chatgpt·ai作画·小程序·deepseek·deepseek-v3
冷琴199633 分钟前
基于Python+Vue开发的反诈视频宣传管理系统源代码
开发语言·vue.js·python
zhrb1 小时前
打开Firefox自动打开hao360.hjttif.com标签解决方案
前端·firefox
安大桃子1 小时前
Cesium实现深色地图效果
前端·gis·cesium
程楠楠&M1 小时前
uni-app(位置1)
前端·javascript·uni-app·node.js
破z晓1 小时前
uniapp 整合openlayers 编辑图形文件并上传到服务器
前端·javascript·uni-app
码农君莫笑1 小时前
Linux系统上同时打印到物理打印机并生成PDF副本方法研究
linux·前端·chrome·打印·信管通