1- import type { MaybeRefOrGetter , Reactive } from 'vue'
1+ import type { ComputedRef , MaybeRef , Reactive } from 'vue'
22import { computed , inject , provide , toValue } from 'vue'
33import { useRoute , viewDepthKey } from 'vue-router'
4- import { isBoolean } from '../utils'
4+ import { isBoolean , isFunction } from '../utils'
5+
6+ export type ExactValue = boolean | number | null
57
68export interface UseExactViewOptions {
79 /**
@@ -10,7 +12,7 @@ export interface UseExactViewOptions {
1012 * - number: 设置为数字时,将精准匹配对应路由的视图组件,且在调用该函数的组件下所有视图组件**支持再嵌套** `<RouterView>`!
1113 * - null: 默认值,将还原 `<RouterView>` 渲染逻辑
1214 */
13- exact : MaybeRefOrGetter < boolean | number | null >
15+ exact : MaybeRef < ExactValue > | ComputedRef < ExactValue > | ( ( viewDepth : number ) => ExactValue )
1416}
1517
1618export function useExactView ( options : UseExactViewOptions | Reactive < UseExactViewOptions > ) : void {
@@ -19,8 +21,10 @@ export function useExactView(options: UseExactViewOptions | Reactive<UseExactVie
1921 provide (
2022 viewDepthKey ,
2123 computed ( ( ) => {
22- const exactValue = toValue ( options . exact )
2324 const viewDepthValue = toValue ( viewDepth )
25+ const exactValue = isFunction ( options . exact )
26+ ? options . exact ( viewDepthValue )
27+ : toValue ( options . exact )
2428
2529 if ( exactValue == null ) {
2630 return viewDepthValue
0 commit comments