Popup 弹窗
基础用法
弹出位置通过 position
属性设置,可设置为 top
bottom
left
right
,默认 center
html
<vz-button block @click="handleShowPopup">弹出弹窗</vz-button>
<vz-popup v-model:show="isShowPopup" position="center" overlay-closeable>
<view>内容</view>
</vz-popup>
typescript
import { ref } from "vue";
const isShowPopup = ref(false);
function handleShowPopup() {
isShowPopup.value = true;
}
内容滚动
html
<vz-button block @click="handleShowPopup">弹出弹窗</vz-button>
<vz-popup v-model:show="isShowPopup" position="center" overlay-closeable>
<view class="popup">
<scroll-view scroll-y class="popup_scroll">
<view class="popup_content">
<view v-for="item in 100" :key="item">{{ item }}</view>
</view>
</scroll-view>
</view>
</vz-popup>
typescript
import { ref } from "vue";
const isShowPopup = ref(false);
function handleShowPopup() {
isShowPopup.value = true;
}
scss
.popup {
padding: 30rpx;
width: 100%;
height: 100%;
&_scroll {
width: 300rpx; // top 或 bottom 时 100%
height: 300rpx; // left 或 right 时 100%
}
&_content {
text-align: center;
}
}
抽离组件
MyPopup.vue
html
<vz-popup :show="show" position="center" @update:show="handleUpdateShow" @open="handleOpen" @close="handleClose">
<view>内容</view>
</vz-popup>
typescript
interface Props {
show: boolean;
}
const props = withDefaults(defineProps<Props>(), {
show: false,
});
const emit = defineEmits(["update:show"]);
function handleUpdateShow() {
emit("update:show", false);
}
function handleOpen() {
// OPEN
}
function handleClose() {
// CLOSE
}
MyPage.vue
html
<vz-button block @click="handleShowPopup">弹出弹窗</vz-button>
<MyPopup v-model:show="isShowPopup" :position="position" />
typescript
import MyPopup from "**/MyPopup";
import { ref } from "vue";
const isShowPopup = ref(false);
function handleShowPopup() {
isShowPopup.value = true;
}
Props
属性名 | 说明 | 类型 | 默认值 | 样式变量 |
---|---|---|---|---|
v-model:show | 是否显示弹窗 | boolean | false | - |
position | 弹出位置 | center / top / bottom / left / right | center | - |
z-index | z-index | number / string | calc(var(--vz-z-index) + 100) | --vz-popup-z-index |
background | 背景。透明 transparent | string | --vz-bg-color | --vz-popup-background |
radius | 圆角 | string / number | 0rpx | --vz-popup-radius |
closeable | 是否显示关闭按钮 | boolean | true | - |
close-icon | 关闭按钮图标 | icon | vz-icon-close | - |
close-size | 关闭按钮尺寸 | string / number | --vz-font-size-large | --vz-popup-close-size |
close-color | 关闭按钮颜色 | string | --vz-color-info | --vz-popup-close-color |
close-position | 关闭按钮位置 | top-right / top-left / bottom-left / bottom-right | top-right | - |
close-edge | 关闭按钮据边缘距离 | string / number | 20rpx | --vz-popup-close-edge |
overlay | 是否显示遮罩层 | boolean | true | - |
overlay-closeable | 点击遮罩层是否关闭弹窗 | boolean | false | - |
overlay-background | 遮罩层背景 | overlay | - | - |
animation | 是否使用 animation 动画 | boolean | false | - |
duration | 动画时长(设置为 0 可关闭动画)。单位 ms | number | 250 | - |
safe-area-inset-bottom | 是否开启顶部安全区适配 | boolean | false | - |
safe-area-inset-top | 是否开启底部安全区适配 | boolean | false | - |
navbar-height | 自定义 navbar 高度。默认单位 px | string / number / "auto" | --window-top | --vz-popup-navbar-height |
tabbar-height | 自定义 tabbar 高度。默认单位 px | string / number / | --window-bottom | --vz-popup-tabbar-height |
i-class | 根节点样式类 | string | - | - |
i-style | 弹窗样式 | Vue.StyleValue | - | - |
相关说明
弹窗不覆盖
WEB
端默认的navbar
及tabbar
。如需覆盖(仅WEB
端),设置z-index
层级高于998
(uni
默认),同时设置navbarHeight: 0px
或tabbarHeight: 0px
弹窗覆盖自定义
navbar
及tabbar
。如需不覆盖,设置z-index
层级低于自定义navbar
及tabbar
(vz
默认500
),同时设置navbarHeight
或tabbarHeight
为对应的自定义navbar
或tabbar
高度(不包含安全区域,需另外设置safeAreaInsetTop: true
或safeAreaInsetBottom: true
)如使用本组件的
navbar
或tabbar
,设置navbar-height: auto
或tabbar-height: auto
,会自动获取相应高度
Events
事件名 | 说明 | 参数 |
---|---|---|
open | 打开时触发 | - |
opened | 打开动画结束时触发 | - |
close | 关闭时触发 | - |
closed | 关闭动画结束时触发 | - |
Slots
插槽名 | 说明 |
---|---|
default | 默认插槽 |
CSS
变量名 | 默认值 | 描述 |
---|---|---|
--vz-popup-offset-y | 0px | 弹窗居中时垂直偏移量 |
SCSS
scss
$popup: (
"z-index": calc(var(--vz-z-index) + 100)),
"background": var(--vz-bg-color),
"radius": 0rpx,
"close-size": var(--vz-font-size-large),
"close-color": var(--vz-color-info),
"close-edge": 20rpx,
);