Skip to content

Commit

Permalink
fix: 兼容vue2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
zuofenghua committed Jul 12, 2022
1 parent c908056 commit e70f4a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
14 changes: 10 additions & 4 deletions src/utils/lifeCircle.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down

0 comments on commit e70f4a0

Please sign in to comment.