May 07, 2021 Vant
Pop-up layer containers for displaying pop-up windows, informational tips, and more, supporting multiple pop-up overlays
import Vue from 'vue';
import { Popup } from 'vant';
Vue.use(Popup);
Control whether the pop-up layer is displayed through v-model
<van-cell is-link @click="showPopup">展示弹出层</van-cell>
<van-popup v-model="show">内容</van-popup>
export default {
data() {
return {
show: false
}
},
methods: {
showPopup() {
this.show = true;
}
}
};
By setting the pop-up position by theposition property, the default center pop-up can be set to top, bottom, left, right
<van-popup
v-model="show"
position="top"
:style="{ height: '20%' }"
/>
When you set the closeable property, the off icon appears in the upper right corner of the pop-up layer, and you can customize the icon with the close-icon property, which allows you to customize the icon position
<van-popup
v-model="show"
closeable
position="bottom"
:style="{ height: '20%' }"
/>
<!-- 自定义图标 -->
<van-popup
v-model="show"
closeable
close-icon="close"
position="bottom"
:style="{ height: '20%' }"
/>
<!-- 图标位置 -->
<van-popup
v-model="show"
closeable
close-icon-position="top-left"
position="bottom"
:style="{ height: '20%' }"
/>
When theround property is set, the pop-up window adds different fillet styles depending on where it pops up
<van-popup
v-model="show"
round
position="bottom"
:style="{ height: '20%' }"
/>
The eject layer is mounted to the component location by default, and the mount location can be specified by the get-container property
<!-- 挂载到 body 节点下 -->
<van-popup v-model="show" get-container="body" />
<!-- 挂载到 #app 节点下 -->
<van-popup v-model="show" get-container="#app" />
<!-- 通过函数指定挂载位置 -->
<van-popup v-model="show" :get-container="getContainer" />
export default {
methods: {
// 返回一个特定的 DOM 节点,作为挂载的父节点
getContainer() {
return document.querySelector('.my-container');
}
}
}
Note: Components that use the get-container property cannot be root nodes
Parameters | Description | Type | The default |
---|---|---|---|
v-model | Whether the current component is displayed | boolean |
false
|
overlay | Whether to display the mask layer | boolean |
true
|
position |
Pop-up location, optional value
top
bottom
right
left
|
string |
center
|
overlay-class | Custom matte layer class name | string | - |
overlay-style | Custom matte layer styles | object | - |
duration | Animation length, in seconds | number | string |
0.3
|
round
v2.0.7
|
Whether to display fillets | boolean |
false
|
lock-scroll | Whether to lock the background scroll | boolean |
true
|
lazy-render | Whether the node is rendered when the bullet layer is displayed | boolean |
true
|
close-on-popstate
v2.2.10
|
Whether to close automatically when the page is rolled back | boolean |
false
|
close-on-click-overlay | Whether to close after tapping the matte layer | boolean |
true
|
closeable
v2.2.0
|
Whether to display the close icon | boolean |
false
|
close-icon
v2.2.0
|
Close the icon name or picture link | string |
cross
|
close-icon-position
v2.2.2
|
Turn off the icon position, with an optional
top-left
bottom-left
bottom-right
|
string |
top-right
|
transition |
The name of the animation class, equivalent to
the name property
of
name
|
string | - |
get-container | Specifies the node that is mounted | string | () => Element | - |
safe-area-inset-bottom
v2.2.1
|
Whether to turn on the bottom safety zone to fit | boolean |
false
|
The name of the event | Description | Callback parameters |
---|---|---|
Click | Triggered when you click on the pop-up layer | event: Event |
open | Triggered when the pop-up layer is opened | - |
opened | Open the pop-up layer and trigger after the animation ends | - |
close | Triggered when the ejection layer is closed | - |
closed | The pop-up layer is closed and triggered after the animation ends | - |
click-overlay | Triggered when the mask layer is clicked | - |