123456789101112131415161718192021222324252627282930 |
- import {
- nextTick,
- onActivated,
- onDeactivated,
- onMounted,
- onUnmounted
- } from 'vue'
- type HookArgs = (...args: any) => () => any
- export const useViewStack = (hook: HookArgs) => {
- let destroy: ReturnType<HookArgs>
- const deHandler = () => {
- if (destroy) {
- destroy()
- destroy = null
- }
- }
- const handler = () => {
- nextTick(() => {
- if (!destroy) {
- destroy = hook()
- }
- })
- }
- onActivated(handler)
- onMounted(handler)
- onDeactivated(deHandler)
- onUnmounted(deHandler)
- }
|