popup 弹窗
支持 5 种方式的弹层
type
: top
,bottom
,left
,right
,center
动画方式: none
,slider
,fade
vue
<template>
<jp-section-selector :current="-1" vibrate-short :list="['上方弹出', '下方弹出', '左方弹出', '右方弹出']" @change="change1"></jp-section-selector>
<jp-popup ref="filter1" height="300px" popup-id="1" transition="slider" type="top">
<view>你好你好</view>
</jp-popup>
<jp-popup ref="filter2" height="300px" popup-id="2" transition="slider" type="bottom">
<view>你好你好</view>
</jp-popup>
<jp-popup ref="filter3" height="100vh" width="80vw" popup-id="3" transition="slider" type="left">
<view>你好你好</view>
</jp-popup>
<jp-popup ref="filter4" height="100vh" width="80vw" popup-id="4" transition="slider" type="right">
<view>你好你好</view>
</jp-popup>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
const filter1 = ref<any>(null)
const filter2 = ref<any>(null)
const filter3 = ref<any>(null)
const filter4 = ref<any>(null)
onMounted(() => {
filter1.value.show()
})
const change1 = (index: number) => {
if (index === 0) {
filter1.value.show()
}
if (index === 1) {
filter2.value.show()
}
if (index === 2) {
filter3.value.show()
}
if (index === 3) {
filter4.value.show()
}
}
</script>
initBeforeOpen
是否在弹框弹出时就触发 onMounted,如果是列表页面,一般不会开启
如果 popup 内的组件是单独封装出去的一个 vue 文件:
initBeforeOpen
这个属性决定了我们在调用 popup 的 show 方法的时候,会不会触发 popup 内部组件的 onMounted 方法。
使用注意点
1、在 input 组件上弹出 popup,popup 上面的点击事件不生效,input 会优先响应点击事件。
2、popup 的高度设置很重要,popup 内部有 scroll-view 时,注意 scroll-view 的高度设置
props
属性名 | 类型 | 默认值 | 描述 |
---|---|---|---|
type | String | "center" | "left", "right", "top", "bottom", "center" |
transition | String | "slider" | "none", "slider", "fade" |
backgroundColor | String | "#fff" | "transparent" |
active | Boolean | false | 是否打开? |
height | String | "100%" | 高度 |
width | String | "100%" | 宽度 |
top | String | "0" | 到顶距离 |
bottom | String | "0" | 到下边距离 |
left | String | "0" | 到左边距离 |
right | String | "0" | 到右边距离 |
popupId | String/Number | 0 | 唯一 id |
maskShow | Boolean | true | 是否有遮罩 |
maskClick | Boolean | true | mask 是否有 点击事件 |
closeCallback | Function | ()=>{} | 关闭回调 |
initBeforeOpen | Boolean | true | show()调用时初始化组件 |