import{o as s,a,y as n}from"./vue-libs.b44bc779.js";const e={class:"van-doc-markdown-body"},o=n(`

Popup

Intro

Used to display pop-up windows, information prompts, etc., and supports multiple pop-up layers to display.

Install

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

import { createApp } from 'vue';
import { Popup } from 'vant';

const app = createApp();
app.use(Popup);

Usage

Basic Usage

<van-cell is-link @click="showPopup">Show Popup</van-cell>
<van-popup v-model:show="show">Content</van-popup>
import { ref } from 'vue';

export default {
  setup() {
    const show = ref(false);
    const showPopup = () => {
      show.value = true;
    };
    return {
      show,
      showPopup,
    };
  },
};

Position

Use position prop to set popup display position.

<van-popup v-model:show="show" position="top" :style="{ height: '30%' }" />

Close Icon

<van-popup
  v-model:show="show"
  closeable
  position="bottom"
  :style="{ height: '30%' }"
/>
<!-- Custom Icon -->
<van-popup
  v-model:show="show"
  closeable
  close-icon="close"
  position="bottom"
  :style="{ height: '30%' }"
/>
<!-- Icon Position -->
<van-popup
  v-model:show="show"
  closeable
  close-icon-position="top-left"
  position="bottom"
  :style="{ height: '30%' }"
/>

Round Corner

<van-popup
  v-model:show="show"
  round
  position="bottom"
  :style="{ height: '30%' }"
/>

Get Container

Use teleport prop to specify mount location.

<!-- teleport to body -->
<van-popup v-model:show="show" teleport="body" />

<!-- teleport to #app -->
<van-popup v-model:show="show" teleport="#app" />

API

Props

AttributeDescriptionTypeDefault
v-model:showWhether to show popupbooleanfalse
overlayWhether to show overlaybooleantrue
positionCan be set to top bottom right leftstringcenter
overlay-classCustom overlay classstring | Array | object-
overlay-styleCustom overlay styleobject-
durationTransition duration, unit secondnumber | string0.3
roundWhether to show round cornerbooleanfalse
lock-scrollWhether to lock background scrollbooleantrue
lazy-renderWhether to lazy render util appearedbooleantrue
close-on-popstateWhether to close when popstatebooleanfalse
close-on-click-overlayWhether to close when overlay is clickedbooleantrue
closeableWhether to show close iconbooleanfalse
close-iconClose icon namestringcross
close-icon-positionClose Icon Position, can be set to top-left bottom-left bottom-rightstringtop-right
before-close v3.1.4Callback function before close(action: string) => boolean | Promise<boolean>-
icon-prefix v3.0.18Icon className prefixstringvan-icon
transitionTransition, equivalent to name prop of transitionstring-
transition-appearWhether to apply transition on initial renderbooleanfalse
teleportSpecifies a target element where Popup will be mountedstring | Element-
safe-area-inset-topWhether to enable top safe area adaptationbooleanfalse
safe-area-inset-bottomWhether to enable bottom safe area adaptationbooleanfalse

Events

EventDescriptionArguments
clickEmitted when Popup is clickedevent: MouseEvent
click-overlayEmitted when overlay is clickedevent: MouseEvent
click-close-iconEmitted when close icon is clickedevent: MouseEvent
openEmitted when opening Popup-
closeEmitted when closing Popup-
openedEmitted when Popup is opened-
closedEmitted when Popup is closed-

Slots

NameDescription
defaultContent of Popup
overlay-content v3.0.18Content of Popup overlay

Types

The component exports the following type definitions:

import type {
  PopupProps,
  PopupPosition,
  PopupInstance,
  PopupCloseIconPosition,
} 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-popup-background-colorvar(--van-background-color-light)-
--van-popup-transitiontransform var(--van-animation-duration-base)-
--van-popup-round-border-radius16px-
--van-popup-close-icon-size22px-
--van-popup-close-icon-colorvar(--van-gray-5)-
--van-popup-close-icon-margin16px-
--van-popup-close-icon-z-index1-
`,16),d=[o],h={__name:"README",setup(l,{expose:t}){return t({frontmatter:{}}),(c,r)=>(s(),a("div",e,d))}};export{h as default};