Skip to content
目录

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

属性名类型默认值描述
typeString"center""left", "right", "top", "bottom", "center"
transitionString"slider""none", "slider", "fade"
backgroundColorString"#fff""transparent"
activeBooleanfalse是否打开?
heightString"100%"高度
widthString"100%"宽度
topString"0"到顶距离
bottomString"0"到下边距离
leftString"0"到左边距离
rightString"0"到右边距离
popupIdString/Number0唯一 id
maskShowBooleantrue是否有遮罩
maskClickBooleantruemask 是否有 点击事件
closeCallbackFunction()=>{}关闭回调
initBeforeOpenBooleantrueshow()调用时初始化组件

©2022 By 绝配移动端组件库