vue3+vant中自定义隐藏DropdownMenu下拉菜单

一、概述

需求:当点击确定按钮时隐藏下拉菜单。

主要使用的方法:ref 标识当前组件 van-dropdown-item ,当点击确定按钮时通过 getCurrentInstance 来获取组件身上的属性方法。

效果图:

二、实现方式

<template>
  <van-dropdown-menu>
      <van-dropdown-item title="更多筛选" ref="sureScreen">
          此处代码省略............
          <div class="shiftBtn">
            <div class="defaultBtn btn">
              <van-button type="default" block round @click="resetMoreScreen">
                重置
              </van-button>
            </div>
            <div class="primaryBtn btn">
              <van-button type="primary" block round @click="onSureMoreScreen">
                确定
              </van-button>
            </div>
          </div>
       </van-dropdown-item>
    </van-dropdown-menu>
</template>

<script setup>
import { getCurrentInstance, ref } from "vue";
// 获取当前组件实例
const instance = getCurrentInstance();
// 确定更多筛选
const onSureMoreScreen = () => {
   // 隐藏更多筛选
  instance.proxy.$refs.sureScreen.toggle();
}
</script>

<style>
</style>

 

posted @   CodeFan*  阅读(2167)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
点击右上角即可分享
微信分享提示