Python私教张大鹏 Vue3整合AntDesignVue之Dropdown 下拉菜单

基本用法

核心代码:

<template>
  <a-dropdown>
    <a class="ant-dropdown-link" @click.prevent>
      Hover me
      <DownOutlined />
    </a>
    <template #overlay>
      <a-menu>
        <a-menu-item>
          <a href="javascript:;">1st menu item</a>
        </a-menu-item>
        <a-menu-item>
          <a href="javascript:;">2nd menu item</a>
        </a-menu-item>
        <a-menu-item>
          <a href="javascript:;">3rd menu item</a>
        </a-menu-item>
      </a-menu>
    </template>
  </a-dropdown>
</template>
<script lang="ts" setup>
import {
     
      DownOutlined } from '@ant-design/icons-vue';
</script>

vue3示例:

<script setup>
import {
     
     DownOutlined} from "@ant-design/icons-vue";
</script>
<template>
  <a-dropdown>
    <a href="" @click.prevent>
      下拉菜单
      <DownOutlined/>
    </a>
    <template #overlay>
      <a-menu>
        <a-menu-item>
          <a href="#">选项1</a>
        </a-menu-item>
        <a-menu-item>
          <a href="#">选项2</a>
        </a-menu-item>
        <a-menu-item>
          <a href="#">选项3</a>
        </a-menu-item>
      </a-menu>
    </template>
  </a-dropdown>
</template>

在这里插入图片描述

右键菜单

默认是移入触发菜单,可以点击鼠标右键触发。

核心代码:

<template>
  <a-dropdown :trigger="['contextmenu']">
    <div
      :style="{
        textAlign: 'center',
        background: '#f7f7f7',
        height: '200px',
        lineHeight: '200px',
        color: '#777',
      }"
    >
      Right Click on here
    </div>
    <template #overlay>
      <a-menu>
        <a-menu-item key="1">1st menu item</a-menu-item>
        <a-menu-item key="2">2nd menu item</a-menu-item>
        <a-menu-item key="3">3rd menu item</a-menu-item>
      </a-menu>
    </template>
  </a-dropdown>
</template>

vue3示例:

<script setup>
import {
     
     DownOutlined} from "@ant-design/icons-vue";
</script>
<template>
  <a-dropdown  :trigger="['contextmenu']">
    <div class="w-72 h-32 bg-indigo-500"></div>
    <template #overlay>
      <a-menu>
        <a-menu-item>
          <a href="#">选项1</a>
        </a-menu-item>
        <a-menu-item>
          <a href="#">选项2</a>
        </a-menu-item>
        <a-menu-item>
          <a href="#">选项3</a>
        </a-menu-item>
      </a-menu>
    </template>
  </a-dropdown>
</template>

在这里插入图片描述

案例:分割线和不可用菜单项

核心代码:

<template>
  <a-dropdown>
    <a class="ant-dropdown-link" @click.prevent>
      Hover me
      <DownOutlined />
    </a>
    <template #overlay>
      <a-menu>
        <a-menu-item key="0">
          <a target="_blank" rel="noopener noreferrer" href="http://www.alipay.com/">
            1st menu item
          </a>
        </a-menu-item>
        <a-menu-item key="1">
          <a target="_blank" rel="noopener noreferrer" href="http://www.taobao.com/">
            2nd menu item
          </a>
        </a-menu-item>
        <a-menu-divider />
        <a-menu-item key="3" disabled
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

源滚滚AI Python私教10年

创业不易,请打赏支持我一点吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值