Skip to content

Popover - Vant 4

Popover

Intro

Used to display some content on top of another.

Install

Register component globally via app.use, refer to Component Registration for more registration ways.

js
import { createApp } from'vue'; import { Popover } from'vant'; const app = createApp(); app.use(Popover);

Usage

Basic Usage

html
js
import { ref } from'vue'; import { showToast } from'vant'; exportdefault { setup() { const showPopover = ref(false); const actions = [ { text: 'Option 1' }, { text: 'Option 2' }, { text: 'Option 3' }, ]; constonSelect = (action) => showToast(action.text); return { actions, onSelect, showPopover, }; }, };

Dark theme

Using the theme prop to change the style of Popover.

html
js
import { ref } from'vue'; exportdefault { setup() { const showPopover = ref(false); const actions = [ { text: 'Option 1' }, { text: 'Option 2' }, { text: 'Option 3' }, ]; return { actions, showPopover, }; }, };

Horizontal

After setting the actions-direction prop to horizontal, the actions will be arranged horizontally.

html
js
import { ref } from'vue'; exportdefault { setup() { const showPopover = ref(false); const actions = [ { text: 'Option 1' }, { text: 'Option 2' }, { text: 'Option 3' }, ]; return { actions, showPopover, }; }, };

Placement

html

placement supports the following values:

bash
top # Top middle top-start # Top left top-end # Top right left # Left middle left-start # Left top left-end # Left bottom right # Right middle right-start # Right top right-end # Right bottom bottom # Bottom middle bottom-start # Bottom left bottom-end # Bottom right

Show Icon

html
js
import { ref } from'vue'; exportdefault { setup() { const showPopover = ref(false); const actions = [ { text: 'Option 1', icon: 'add-o' }, { text: 'Option 2', icon: 'music-o' }, { text: 'Option 3', icon: 'more-o' }, ]; return { actions, showPopover, }; }, };

Disable Action

Using the disabled option to disable an action.

html
js
import { ref } from'vue'; exportdefault { setup() { const showPopover = ref(false); const actions = [ { text: 'Option 1', disabled: true }, { text: 'Option 2', disabled: true }, { text: 'Option 3' }, ]; return { actions, showPopover, }; }, };

Custom Content

html
js
import { ref } from'vue'; exportdefault { setup() { const showPopover = ref(false); return { showPopover }; }, };

Uncontrolled

You can use Popover as a controlled or uncontrolled component:

  • When binding v-model:show, Popover is a controlled component, and the display of the component is completely controlled by the value of v-model:show.
  • When v-model:show is not used, Popover is an uncontrolled component. You can pass in a default value through the show prop, and the display is controlled by the component itself.
html
js
import { ref } from'vue'; import { showToast } from'vant'; exportdefault { setup() { const actions = [ { text: 'Option 1' }, { text: 'Option 2' }, { text: 'Option 3' }, ]; constonSelect = (action) => showToast(action.text); return { actions, onSelect, }; }, };

API

Props

AttributeDescriptionTypeDefault
v-model:showWhether to show Popoverbooleanfalse
actionsActionsPopoverAction[][]
actions-direction v4.4.1Direction of actions, can be set to horizontalPopoverActionsDirectionvertical
placementPlacementPopoverPlacementbottom
themeTheme, can be set to darkPopoverThemelight
triggerTrigger mode, can be set to manualPopoverTriggerclick
durationTransition duration, unit second*numberstring*
offsetDistance to reference[number, number][0, 8]
overlayWhether to show overlaybooleanfalse
overlay-classCustom overlay class*stringArray
overlay-styleCustom overlay styleobject-
show-arrowWhether to show arrowbooleantrue
close-on-click-actionWhether to close when clicking actionbooleantrue
close-on-click-outsideWhether to close when clicking outsidebooleantrue
close-on-click-overlayWhether to close when clicking overlaybooleantrue
teleportSpecifies a target element where Popover will be mounted*stringElement*
icon-prefixIcon className prefixstringvan-icon

Data Structure of PopoverAction

KeyDescriptionType
textAction Textstring
iconIconstring
colorAction Colorstring
disabledWhether to be disabledboolean
classNameclassName of the option*string

Events

EventDescriptionArguments
selectEmitted when an action is clickedaction: PopoverAction, index: number
openEmitted when opening Popover-
closeEmitted when closing Popover-
openedEmitted when Popover is opened-
closedEmitted when Popover is closed-
click-overlayEmitted when overlay is clickedevent: MouseEvent

Slots

NameDescriptionSlotProps
defaultCustom content-
referenceReference Element-
actionCustom the content of option{ action: PopoverAction, index: number }

Types

The component exports the following type definitions:

ts
importtype { PopoverProps, PopoverTheme, PopoverAction, PopoverActionsDirection, PopoverTrigger, PopoverPlacement, } from'vant';

Theming

CSS Variables

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

NameDefault ValueDescription
--van-popover-arrow-size6px-
--van-popover-radiusvar(--van-radius-lg)-
--van-popover-action-width128px-
--van-popover-action-height44px-
--van-popover-action-font-sizevar(--van-font-size-md)-
--van-popover-action-line-heightvar(--van-line-height-md)-
--van-popover-action-icon-size20px-
--van-popover-horizontal-action-height34px-
--van-popover-horizontal-action-icon-size16px-
--van-popover-light-text-colorvar(--van-text-color)-
--van-popover-light-backgroundvar(--van-background-2)-
--van-popover-light-action-disabled-text-colorvar(--van-text-color-3)-
--van-popover-dark-text-colorvar(--van-white)-
--van-popover-dark-background#4a4a4a-

| --van-popover-dark-action-disabled-text-color | var(--van-text-color-2) | - |

Enterprise-level mobile solution based on Vant