forked from cuixiaorui/mini-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc8aacf
commit 9bfbf24
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const publicPropertiesMap = { | ||
// 当用户调用 instance.proxy.$emit 时就会触发这个函数 | ||
$emit: (i) => i.emit, | ||
}; | ||
|
||
export const PublicInstanceProxyHandlers = { | ||
get({ _: instance }, key) { | ||
// 用户访问 proxy[key] | ||
// 这里就匹配一下看看是否有对应的 function | ||
// 有的话就直接调用这个 function | ||
console.log("触发 proxy 的 hook"); | ||
|
||
const publicGetter = publicPropertiesMap[key]; | ||
|
||
if (publicGetter) { | ||
return publicGetter(instance); | ||
} | ||
}, | ||
}; |