From e70f4a06be5b67ac0da37d70607d5c18f42719cf Mon Sep 17 00:00:00 2001 From: zuofenghua <11100776@bbktel.com> Date: Tue, 12 Jul 2022 11:47:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=BC=E5=AE=B9vue2.7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/utils/lifeCircle.ts | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 137c534..822c300 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ahooks-vue", - "version": "0.13.1", + "version": "0.13.3", "description": "ahooks-vue", "types": "dist/src/index.d.ts", "repository": "https://github.com/dewfall123/ahooks-vue.git", diff --git a/src/utils/lifeCircle.ts b/src/utils/lifeCircle.ts index 75919bb..ca0a9b8 100644 --- a/src/utils/lifeCircle.ts +++ b/src/utils/lifeCircle.ts @@ -1,10 +1,16 @@ import { getCurrentInstance, onMounted } from 'vue-demi'; export function safeOnMounted(hook: () => any) { - let instance = getCurrentInstance(); - // @ts-ignore - instance = instance?.proxy || instance; - if (instance?.isMounted || (instance as any)._isMounted) { + const instance = getCurrentInstance(); + + // fix 兼容vue2.7 + if ( + // @ts-ignore + instance?.proxy?._isMounted || + instance?.isMounted || + // @ts-ignore + instance._isMounted + ) { hook(); } else { onMounted(hook);