Popup 弹出层

Popup 组件会响应返回按钮和返回手势。当返回时,会关闭弹出层,而不是回到上一页。

示例

基础用法

<Popup bind:visible={popup.center} position="center">
  <div>居中</div>
</Popup>

页面跳转

请注意:Popup 打开状态下,如果需要跳转页面,请直接跳转,Popup 会自动关闭。

<script lang="ts">
  import { delay } from 'sun-parakeet'

  let visible = $state(false)

  // 直接跳转
  function nextStep() {
    goto('/next-step')
  }
</script>

<Popup bind:visible position="center">
  <Button onclick={() => nextPage()}>跳转</Button>
</Popup>

Popup

属性

属性 说明 类型 默认值
visible 是否显示 boolean $bindable(false)
position 弹出位置 'center' | 'top' | 'right' | 'bottom' | 'left' 'bottom'
noMask 不展示遮罩 boolean false
keepOpenOnClickMask 阻止点击遮罩关闭 boolean false
destroyOnClose 关闭时销毁子元素 boolean false

事件

事件 说明 类型
onClose 关闭时触发 () => void