fant-mini-plus
Version:
fant-mini-plus是一个基于Vue3和TypeScript的uni-app高效UI组件库,提供丰富的组件和样式,帮助开发者快速构建高质量的移动应用。
44 lines (39 loc) • 1.02 kB
text/typescript
/*
* @Author: weisheng
* @Date: 2022-12-14 17:33:21
* @LastEditTime: 2023-05-19 15:55:52
* @LastEditors: weisheng
* @Description:
* @FilePath: \fant-mini-plus\src\uni_modules\fant-mini-plus\components\hd-popup\index.ts
* 记得注释
*/
import { type InjectionKey, type Ref, nextTick, provide, ref } from 'vue'
import type { Popup } from './types'
/**
* usePopup 用到的key
*
* @internal
*/
export const popupDefaultKey = Symbol('__POPUP_') as InjectionKey<Ref<boolean>>
export function usePopup(selector: string = ''): Popup {
const popupShow = ref<boolean>(false) // 是否展示popup
const popupKey = selector ? '__POPUP_' + selector : popupDefaultKey
provide(popupKey, popupShow)
const showPopup = () => {
if (popupShow.value) {
popupShow.value = false
nextTick(() => {
popupShow.value = true
})
} else {
popupShow.value = true
}
}
const closePopup = () => {
popupShow.value = false
}
return {
showPopup,
closePopup
}
}