/*! For license information please see 5412.fcb8169a.js.LICENSE.txt */ (self.webpackChunk=self.webpackChunk||[]).push([["5412"],{96237:function(s,n,a){"use strict";a.r(n);var t=a("80681");let l=["innerHTML"];n.default={setup:()=>({html:""}),render:()=>((0,t.wg)(),(0,t.iD)("div",{class:"van-doc-markdown-body",innerHTML:'
Used to display some content on top of another.
\nRegister component globally via app.use
, refer to Component Registration for more registration ways.
import { createApp } from 'vue';\nimport { Popover } from 'vant';\n\nconst app = createApp();\napp.use(Popover);\n
\n<van-popover v-model:show="showPopover" :actions="actions" @select="onSelect">\n <template #reference>\n <van-button type="primary">Light Theme</van-button>\n </template>\n</van-popover>\n
\nimport { ref } from 'vue';\nimport { showToast } from 'vant';\n\nexport default {\n setup() {\n const showPopover = ref(false);\n const actions = [\n { text: 'Option 1' },\n { text: 'Option 2' },\n { text: 'Option 3' },\n ];\n const onSelect = (action) => showToast(action.text);\n\n return {\n actions,\n onSelect,\n showPopover,\n };\n },\n};\n
\nUsing the theme
prop to change the style of Popover.
<van-popover v-model:show="showPopover" theme="dark" :actions="actions">\n <template #reference>\n <van-button type="primary">Dark Theme</van-button>\n </template>\n</van-popover>\n
\nimport { ref } from 'vue';\n\nexport default {\n setup() {\n const showPopover = ref(false);\n const actions = [\n { text: 'Option 1' },\n { text: 'Option 2' },\n { text: 'Option 3' },\n ];\n\n return {\n actions,\n showPopover,\n };\n },\n};\n
\nAfter setting the actions-direction
prop to horizontal
, the actions will be arranged horizontally.
<van-popover\n v-model:show="showPopover"\n :actions="actions"\n actions-direction="horizontal"\n>\n <template #reference>\n <van-button type="primary">Horizontal</van-button>\n </template>\n</van-popover>\n
\nimport { ref } from 'vue';\n\nexport default {\n setup() {\n const showPopover = ref(false);\n const actions = [\n { text: 'Option 1' },\n { text: 'Option 2' },\n { text: 'Option 3' },\n ];\n\n return {\n actions,\n showPopover,\n };\n },\n};\n
\n<van-popover placement="top" />\n
\nplacement
supports the following values:
top # Top middle\ntop-start # Top left\ntop-end # Top right\nleft # Left middle\nleft-start # Left top\nleft-end # Left bottom\nright # Right middle\nright-start # Right top\nright-end # Right bottom\nbottom # Bottom middle\nbottom-start # Bottom left\nbottom-end # Bottom right\n
\n<van-popover v-model:show="showPopover" :actions="actions">\n <template #reference>\n <van-button type="primary">Show Icon</van-button>\n </template>\n</van-popover>\n
\nimport { ref } from 'vue';\n\nexport default {\n setup() {\n const showPopover = ref(false);\n const actions = [\n { text: 'Option 1', icon: 'add-o' },\n { text: 'Option 2', icon: 'music-o' },\n { text: 'Option 3', icon: 'more-o' },\n ];\n\n return {\n actions,\n showPopover,\n };\n },\n};\n
\nUsing the disabled
option to disable an action.
<van-popover v-model:show="showPopover" :actions="actions">\n <template #reference>\n <van-button type="primary">Disable Action</van-button>\n </template>\n</van-popover>\n
\nimport { ref } from 'vue';\n\nexport default {\n setup() {\n const showPopover = ref(false);\n const actions = [\n { text: 'Option 1', disabled: true },\n { text: 'Option 2', disabled: true },\n { text: 'Option 3' },\n ];\n\n return {\n actions,\n showPopover,\n };\n },\n};\n
\n<van-popover v-model:show="showPopover">\n <van-grid\n square\n clickable\n :border="false"\n column-num="3"\n style="width: 240px;"\n >\n <van-grid-item\n v-for="i in 6"\n :key="i"\n text="Option"\n icon="photo-o"\n @click="showPopover = false"\n />\n </van-grid>\n <template #reference>\n <van-button type="primary">Custom Content</van-button>\n </template>\n</van-popover>\n
\nimport { ref } from 'vue';\n\nexport default {\n setup() {\n const showPopover = ref(false);\n return { showPopover };\n },\n};\n
\nYou can use Popover as a controlled or uncontrolled component:
\nv-model:show
, Popover is a controlled component, and the display of the component is completely controlled by the value of v-model:show
.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.<van-popover :actions="actions" position="top-start" @select="onSelect">\n <template #reference>\n <van-button type="primary">Uncontrolled</van-button>\n </template>\n</van-popover>\n
\nimport { ref } from 'vue';\nimport { showToast } from 'vant';\n\nexport default {\n setup() {\n const actions = [\n { text: 'Option 1' },\n { text: 'Option 2' },\n { text: 'Option 3' },\n ];\n const onSelect = (action) => showToast(action.text);\n return {\n actions,\n onSelect,\n };\n },\n};\n
\nAttribute | \nDescription | \nType | \nDefault | \n
---|---|---|---|
v-model:show | \nWhether to show Popover | \nboolean | \nfalse | \n
actions | \nActions | \nPopoverAction[] | \n[] | \n
actions-direction v4.4.1 | \nDirection of actions, can be set to horizontal | \nPopoverActionsDirection | \nvertical | \n
placement | \nPlacement | \nPopoverPlacement | \nbottom | \n
theme | \nTheme, can be set to dark | \nPopoverTheme | \nlight | \n
trigger | \nTrigger mode, can be set to manual | \nPopoverTrigger | \nclick | \n
duration | \nTransition duration, unit second | \nnumber | string | \n0.3 | \n
offset | \nDistance to reference | \n[number, number] | \n[0, 8] | \n
overlay | \nWhether to show overlay | \nboolean | \nfalse | \n
overlay-class | \nCustom overlay class | \nstring | Array | object | \n- | \n
overlay-style | \nCustom overlay style | \nobject | \n- | \n
show-arrow | \nWhether to show arrow | \nboolean | \ntrue | \n
close-on-click-action | \nWhether to close when clicking action | \nboolean | \ntrue | \n
close-on-click-outside | \nWhether to close when clicking outside | \nboolean | \ntrue | \n
close-on-click-overlay | \nWhether to close when clicking overlay | \nboolean | \ntrue | \n
teleport | \nSpecifies a target element where Popover will be mounted | \nstring | Element | \nbody | \n
icon-prefix | \nIcon className prefix | \nstring | \nvan-icon | \n
Key | \nDescription | \nType | \n
---|---|---|
text | \nAction Text | \nstring | \n
icon | \nIcon | \nstring | \n
color | \nAction Color | \nstring | \n
disabled | \nWhether to be disabled | \nboolean | \n
className | \nclassName of the option | \nstring | Array | object | \n
Event | \nDescription | \nArguments | \n
---|---|---|
select | \nEmitted when an action is clicked | \naction: PopoverAction, index: number | \n
open | \nEmitted when opening Popover | \n- | \n
close | \nEmitted when closing Popover | \n- | \n
opened | \nEmitted when Popover is opened | \n- | \n
closed | \nEmitted when Popover is closed | \n- | \n
click-overlay | \nEmitted when overlay is clicked | \nevent: MouseEvent | \n
Name | \nDescription | \nSlotProps | \n
---|---|---|
default | \nCustom content | \n- | \n
reference | \nReference Element | \n- | \n
action | \nCustom the content of option | \n{ action: PopoverAction, index: number } | \n
The component exports the following type definitions:
\nimport type {\n PopoverProps,\n PopoverTheme,\n PopoverAction,\n PopoverActionsDirection,\n PopoverTrigger,\n PopoverPlacement,\n} from 'vant';\n
\nThe component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.
\nName | \nDefault Value | \nDescription | \n
---|---|---|
--van-popover-arrow-size | \n6px | \n- | \n
--van-popover-radius | \nvar(--van-radius-lg) | \n- | \n
--van-popover-action-width | \n128px | \n- | \n
--van-popover-action-height | \n44px | \n- | \n
--van-popover-action-font-size | \nvar(--van-font-size-md) | \n- | \n
--van-popover-action-line-height | \nvar(--van-line-height-md) | \n- | \n
--van-popover-action-icon-size | \n20px | \n- | \n
--van-popover-horizontal-action-height | \n34px | \n- | \n
--van-popover-horizontal-action-icon-size | \n16px | \n- | \n
--van-popover-light-text-color | \nvar(--van-text-color) | \n- | \n
--van-popover-light-background | \nvar(--van-background-2) | \n- | \n
--van-popover-light-action-disabled-text-color | \nvar(--van-text-color-3) | \n- | \n
--van-popover-dark-text-color | \nvar(--van-white) | \n- | \n
--van-popover-dark-background | \n#4a4a4a | \n- | \n
--van-popover-dark-action-disabled-text-color | \nvar(--van-text-color-2) | \n- | \n