UNPKG

gtht-miniapp-sdk

Version:

gtht-miniapp-sdk 是一套基于 Uniapp + Vue3 框架开发的兼容多端的 UI 组件库

36 lines (35 loc) 875 B
import { getCurrentInstance, onMounted } from 'vue'; import { getBoundingClientRect } from '../../utils'; export function usePopover(selector) { const instance = getCurrentInstance(); let context; let customGetRect; function _inject(value) { context = value; } function getRect() { if (customGetRect) { const tempGetRect = customGetRect; customGetRect = undefined; return tempGetRect(); } if (selector) { return getBoundingClientRect(selector, instance); } } onMounted(() => { context?.register({ getRect, }); }); const show = (getRectFn) => { customGetRect = getRectFn; if (selector || customGetRect) { context?.show(); } }; return { show, _inject, }; }