Skip to content

Popup

A popup layer component used to display popups, information prompts, and other content.

Basic Usage

v-model is the binding value that indicates whether to display the popup layer.

html
<wd-popup v-model="show" custom-style="border-radius:32rpx;" @close="handleClose">
  <text class="custom-txt">Pop Pop Pop</text>
</wd-popup>
css
.custom-txt {
  color: black;
  width: 400rpx;
  height: 400rpx;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 40rpx;
  border-radius: 32rpx;
}

Set position, default is 'center', optional values are 'top', 'right', 'bottom', 'left'.

html
<wd-popup v-model="show" position="top" custom-style="height: 200px;" @close="handleClose"></wd-popup>

Close Button

Set the closable attribute.

html
<wd-popup v-model="show" position="bottom" closable custom-style="height: 200px;" @close="handleClose"></wd-popup>

Disable Mask Click

By setting the close-on-click-modal attribute to false, you can disable the function of closing the popup layer when the user clicks the mask layer.

html
<wd-popup v-model="show" position="bottom" :close-on-click-modal="false" closable custom-style="height: 200px;" @close="handleClose"></wd-popup>

Disable Mask

By setting the modal attribute to false, you can disable the mask layer, allowing users to interact with the underlying content.

html
<wd-popup v-model="show" position="bottom" :modal="false" closable custom-style="height: 200px;" @close="handleClose"></wd-popup>

Enable Bottom Safe Area

By setting the safe-area-inset-bottom attribute to true, you can ensure that the popup layer is not blocked by the bottom safe area when displayed at the bottom.

html
<wd-popup v-model="show" position="bottom" :safe-area-inset-bottom="true" custom-style="height: 200px;" @close="handleClose"></wd-popup>

root-portal

When the root-portal attribute is set to true, the popup will be detached from the page, which can avoid the influence of parent component's transform, filter and other CSS properties on the fixed positioning of the popup.

Different platforms use different implementation schemes:

  • H5: Use Vue 3's teleport feature
  • APP: Use renderjs to move elements to the uni-app root node
  • WeChat Mini Program/Alipay Mini Program: Use root-portal component
  • Other platforms: This feature is not supported
html
<wd-popup v-model="show" root-portal position="center" custom-style="height: 200px;" @close="handleClose">
  <text class="custom-txt">I'm teleported to the root node</text>
</wd-popup>

Tip

This feature is mainly used to solve layering and positioning issues of popups in complex layouts, and it is recommended to enable it only when needed.

Prevent Scroll Penetration

When using the component, you will find that when the content part scrolls to the bottom, continuing to swipe will cause the underlying page to scroll, which is scroll penetration.

Currently, the component can handle some scroll penetration issues through the lock-scroll attribute. However, due to the reasons of the mini-program and APP platforms themselves, scroll penetration will still occur in the popup content area. However, we provide developers with a recommended solution to completely solve scroll penetration:

You can use the page-meta component to dynamically modify the overflow attribute of page-meta.

html
<!-- page-meta can only be the first node in the page -->
<page-meta :page-style="`overflow:${show ? 'hidden' : 'visible'};`"></page-meta>

<wd-popup v-model="show" lock-scroll position="bottom" :safe-area-inset-bottom="true" custom-style="height: 200px;" @close="handleClose"></wd-popup>

Tip

H5 scroll penetration does not need to be handled, the component has enabled lock-scroll by default.

Attributes

AttributeDescriptionTypeOptional ValuesDefaultVersion
v-modelWhether to show popupboolean---
positionPopup positionstringcenter/top/right/bottom/leftcenter-
closableWhether to show close buttonboolean-false-
close-on-click-modalWhether to close when clicking maskboolean-true-
durationAnimation durationnumber/boolean-300(ms)-
z-indexPopup z-indexnumber-10-
custom-styleCustom popup stylestring---
modalWhether to show maskboolean-true-
modal-styleCustom mask stylestring---
hide-when-closeWhether to hide when closedboolean-true-
lazy-renderWhether to enable lazy renderingboolean-true-
safe-area-inset-bottomWhether to enable bottom safe areaboolean-false-
transitionTransition typestringfade/fade-up/fade-down/fade-left/fade-right/slide-up/slide-down/slide-left/slide-right/zoom-in--
lock-scrollWhether to lock background scrollboolean-true0.1.30
root-portalWhether to mount to root nodeboolean-false1.11.0

Events

EventDescriptionParametersVersion
closeTriggered when popup is closed--
click-modalTriggered when mask is clicked--
before-enterTriggered before enter transition starts--
enterTriggered when enter transition starts--
after-enterTriggered when enter transition ends--
before-leaveTriggered before leave transition starts--
leaveTriggered when leave transition starts--
after-leaveTriggered when leave transition ends--

External Style Classes

Class NameDescriptionVersion
custom-classRoot node style-

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.