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
| Attribute | Description | Type | Default |
|---|---|---|---|
| show | Whether to show overlay | boolean | false |
| z-index | z-index | *number | string* |
| duration | Animation duration | *number | string* |
| class-name | ClassName | string | - |
| custom-class | Custom style | object | - |
| lock-scroll | Whether to lock background scroll | boolean | true |
| lazy-render | Whether to lazy render util appeared | boolean | true |
| teleport | Specifies a target element where Overlay will be mounted | *string | Element* |
Events
| Event | Description | Arguments |
|---|---|---|
| click | Emitted when component is clicked | event: MouseEvent |
Slots
| Name | Description |
|---|---|
| default | Default 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.
| Name | Default Value | Description |
|---|---|---|
| --van-overlay-z-index | 1 | - |
| --van-overlay-background | rgba(0, 0, 0, 0.7) | - |