Skip to content

Overlay - Vant 4

Overlay

Intro

Create a mask layer to emphasize specific page elements and prevent users from performing other operations.

Install

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

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

Usage

Basic Usage

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

Embedded Content

Any content can be embedded on the overlay through the default slot.

html

Setting z-index

The default z-index level of the Overlay component is 1. You can set its z-index level using the z-index prop.

html

API

Props

AttributeDescriptionTypeDefault
showWhether to show overlaybooleanfalse
z-indexz-index*numberstring*
durationAnimation duration*numberstring*
class-nameClassNamestring-
custom-classCustom styleobject-
lock-scrollWhether to lock background scrollbooleantrue
lazy-renderWhether to lazy render util appearedbooleantrue
teleportSpecifies a target element where Overlay will be mounted*stringElement*

Events

EventDescriptionArguments
clickEmitted when component is clickedevent: MouseEvent

Slots

NameDescription
defaultDefault slot

Types

The component exports the following type definitions:

ts
importtype { OverlayProps } 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-overlay-z-index1-
--van-overlay-backgroundrgba(0, 0, 0, 0.7)-

Enterprise-level mobile solution based on Vant