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的状态和类型方法所以使用了上面的方式将数据进行了传递,最终效果。

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

相关推荐
前端不太难19 小时前
从 Navigation State 反推架构腐化
前端·架构·react
前端程序猿之路19 小时前
Next.js 入门指南 - 从 Vue 角度的理解
前端·vue.js·语言模型·ai编程·入门·next.js·deepseek
大布布将军20 小时前
⚡️ 深入数据之海:SQL 基础与 ORM 的应用
前端·数据库·经验分享·sql·程序人生·面试·改行学it
川贝枇杷膏cbppg20 小时前
Redis 的 RDB 持久化
前端·redis·bootstrap
D_C_tyu20 小时前
Vue3 + Element Plus | el-table 表格获取排序后的数据
javascript·vue.js·elementui
JIngJaneIL20 小时前
基于java+ vue农产投入线上管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot
天外天-亮21 小时前
v-if、v-show、display: none、visibility: hidden区别
前端·javascript·html
jump_jump21 小时前
手写一个 Askama 模板压缩工具
前端·性能优化·rust
hellotutu21 小时前
vue2 从 sessionStorage 手动取 token 后,手动加入到 header
vue.js·token·session·header
be or not to be21 小时前
HTML入门系列:从图片到表单,再到音视频的完整实践
前端·html·音视频