
Security News
The Code You Didn't Write Is Still Yours to Defend
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.
@ophiuchus/dropdown
Advanced tools
向下弹出的菜单列表。
// 方式1(推荐)
import Vue from 'vue';
import Dropdown from '@ophiuchus/dropdown';
Vue.use(Dropdown);
// 方式2
import Vue from 'vue';
import { DropdownMenu, DropdownItem } from '@ophiuchus/dropdown';
Vue.component(DropdownMenu.name, DropdownMenu);
Vue.component(DropdownItem.name, DropdownItem);
<sf-dropdown-menu>
<sf-dropdown-item v-model="value1" :options="option1" />
<sf-dropdown-item v-model="value2" :options="option2" />
</sf-dropdown-menu>
export default {
data() {
return {
value1: 0,
value2: 'a',
option1: [
{ text: '全部商品', value: 0 },
{ text: '新款商品', value: 1 },
{ text: '活动商品', value: 2 },
],
option2: [
{ text: '默认排序', value: 'a' },
{ text: '好评排序', value: 'b' },
{ text: '销量排序', value: 'c' },
],
};
},
};
通过插槽可以自定义 DropdownItem 的内容,此时需要使用实例上的 toggle 方法手动控制菜单的显示。
<sf-dropdown-menu>
<sf-dropdown-item v-model="value" :options="option" />
<sf-dropdown-item title="筛选" ref="item">
<sf-cell center title="包邮">
<template #right-icon>
<sf-switch v-model="switch1" size="24" active-color="#ee0a24" />
</template>
</sf-cell>
<sf-cell center title="团购">
<template #right-icon>
<sf-switch v-model="switch2" size="24" active-color="#ee0a24" />
</template>
</sf-cell>
<div style="padding: 5px 16px;">
<sf-button type="danger" block round @click="onConfirm">
确认
</sf-button>
</div>
</sf-dropdown-item>
</sf-dropdown-menu>
export default {
data() {
return {
value: 0,
switch1: false,
switch2: false,
option: [
{ text: '全部商品', value: 0 },
{ text: '新款商品', value: 1 },
{ text: '活动商品', value: 2 },
],
};
},
methods: {
onConfirm() {
this.$refs.item.toggle();
},
},
};
通过 active-color 属性可以自定义菜单标题和选项的选中态颜色。
<sf-dropdown-menu active-color="#1989fa">
<sf-dropdown-item v-model="value1" :options="option1" />
<sf-dropdown-item v-model="value2" :options="option2" />
</sf-dropdown-menu>
将 direction 属性值设置为 up,菜单即可向上展开。
<sf-dropdown-menu direction="up">
<sf-dropdown-item v-model="value1" :options="option1" />
<sf-dropdown-item v-model="value2" :options="option2" />
</sf-dropdown-menu>
<sf-dropdown-menu>
<sf-dropdown-item v-model="value1" disabled :options="option1" />
<sf-dropdown-item v-model="value2" disabled :options="option2" />
</sf-dropdown-menu>
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| active-color | 菜单标题和选项的选中态颜色 | string | #ee0a24 |
| direction | 菜单展开方向,可选值为up | string | down |
| z-index | 菜单栏 z-index 层级 | number | string | 10 |
| duration | 动画时长,单位秒 | number | string | 0.2 |
| overlay | 是否显示遮罩层 | boolean | true |
| close-on-click-overlay | 是否在点击遮罩层后关闭菜单 | boolean | true |
| close-on-click-outside | 是否在点击外部元素后关闭菜单 | boolean | true |
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| value | 当前选中项对应的 value,可以通过v-model双向绑定 | number | string | - |
| title | 菜单项标题 | string | 当前选中项文字 |
| options | 选项数组 | Option[] | [] |
| disabled | 是否禁用菜单 | boolean | false |
| lazy-render | 是否在首次展开时才渲染菜单内容 | boolean | true |
| title-class | 标题额外类名 | string | - |
| get-container | 指定挂载的节点,用法示例 | string | () => Element | - |
| 事件名 | 说明 | 回调参数 |
|---|---|---|
| change | 点击选项导致 value 变化时触发 | value |
| open | 打开菜单栏时触发 | - |
| close | 关闭菜单栏时触发 | - |
| opened | 打开菜单栏且动画结束后触发 | - |
| closed | 关闭菜单栏且动画结束后触发 | - |
| 名称 | 说明 |
|---|---|
| default | 菜单内容 |
| title | 自定义菜单项标题 |
通过 ref 可以获取到 DropdownItem 实例并调用实例方法,详见组件实例方法。
| 方法名 | 说明 | 参数 | 返回值 |
|---|---|---|---|
| toggle | 切换菜单展示状态,传 true 为显示,false 为隐藏,不传参为取反 | show?: boolean | - |
| 键名 | 说明 | 类型 |
|---|---|---|
| text | 文字 | string |
| value | 标识符 | number | string |
| icon | 左侧图标名称或图片链接 | string |
组件提供了下列 Less 变量,可用于自定义样式,使用方法请参考主题定制。
| 名称 | 默认值 | 描述 |
|---|---|---|
| @dropdown-menu-height | 48px | - |
| @dropdown-menu-background-color | @white | - |
| @dropdown-menu-box-shadow | 0 2px 12px fade(@gray-7, 12) | - |
| @dropdown-menu-title-font-size | 15px | - |
| @dropdown-menu-title-text-color | @text-color | - |
| @dropdown-menu-title-active-text-color | @red | - |
| @dropdown-menu-title-disabled-text-color | @gray-6 | - |
| @dropdown-menu-title-padding | 0 @padding-xs | - |
| @dropdown-menu-title-line-height | @line-height-lg | - |
| @dropdown-menu-option-active-color | @red | - |
| @dropdown-menu-content-max-height | 80% | - |
| @dropdown-item-z-index | 10 | - |
把 DropdownMenu 嵌套在 Tabs 等组件内部使用时,可能会遇到下拉菜单位置错误的问题。这是因为在 Chrome 浏览器中,transform 元素内部的 fixed 布局会降级成 absolute 布局,导致下拉菜单的布局异常。
将 DropdownItem 的 get-container 属性设置为 body 即可避免此问题:
<sf-dropdown-menu>
<sf-dropdown-item get-container="body" />
<sf-dropdown-item get-container="body" />
</sf-dropdown-menu>
FAQs
### 介绍
We found that @ophiuchus/dropdown demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.