Skip to content

传送门(useTeleport)

useTeleport 是一个跨平台传送门抽象 Hook,弥合 H5 端 Vue <Teleport> 与小程序/App 端 position: fixed 方案之间的差异。

此 API 源码:GitHub

使用方式

vue
<script setup>
import { useTeleport } from 'see-u-ui'

const { isTeleported, targetSelector, isSupported } = useTeleport()

// H5 端:isTeleported = true, targetSelector = 'body'
// 小程序端:isTeleported = false, 使用 position: fixed 兜底
</script>

API

useTeleport(options?)

参数类型默认值说明
options.isEnabledMaybeRef<boolean>true是否启用传送门
options.tostring'body'目标选择器

返回值:

属性/方法类型说明
isTeleportedComputedRef<boolean>是否应使用传送门
targetSelectorComputedRef<string>传送目标选择器
isSupportedboolean当前平台是否支持原生 Teleport(仅 H5 为 true)

辽 ICP 备 2025070134 号