1
1
import type { Key } from '../../../_util/type' ;
2
2
import type { ComputedRef , CSSProperties , InjectionKey , PropType , Ref , UnwrapRef } from 'vue' ;
3
- import { toRef } from 'vue' ;
4
- import { watchEffect } from 'vue' ;
5
- import { defineComponent , inject , provide } from 'vue' ;
3
+ import { defineComponent , inject , provide , toRef } from 'vue' ;
6
4
import type {
7
5
BuiltinPlacements ,
8
6
MenuClickEventHandler ,
@@ -21,7 +19,7 @@ export interface StoreMenuInfo {
21
19
parentKeys : ComputedRef < Key [ ] > ;
22
20
}
23
21
export interface MenuContextProps {
24
- isRootMenu : boolean ;
22
+ isRootMenu : Ref < boolean > ;
25
23
26
24
store : Ref < Record < string , UnwrapRef < StoreMenuInfo > > > ;
27
25
registerMenuInfo : ( key : string , info : StoreMenuInfo ) => void ;
@@ -115,17 +113,17 @@ const MenuContextProvider = defineComponent({
115
113
setup ( props , { slots } ) {
116
114
const menuContext = useInjectMenu ( ) ;
117
115
const newContext = { ...menuContext } ;
118
- watchEffect ( ( ) => {
119
- if ( props . mode !== undefined ) {
120
- newContext . mode = toRef ( props , 'mode' ) ;
121
- }
122
- if ( props . isRootMenu !== undefined ) {
123
- newContext . isRootMenu = props . isRootMenu ;
124
- }
125
- if ( props . overflowDisabled !== undefined ) {
126
- newContext . overflowDisabled = toRef ( props , 'overflowDisabled' ) ;
127
- }
128
- } ) ;
116
+ // 确保传入的属性不会动态增删
117
+ // 不需要 watch 变化
118
+ if ( props . mode !== undefined ) {
119
+ newContext . mode = toRef ( props , 'mode' ) ;
120
+ }
121
+ if ( props . isRootMenu !== undefined ) {
122
+ newContext . isRootMenu = toRef ( props , 'isRootMenu' ) ;
123
+ }
124
+ if ( props . overflowDisabled !== undefined ) {
125
+ newContext . overflowDisabled = toRef ( props , 'overflowDisabled' ) ;
126
+ }
129
127
useProvideMenu ( newContext ) ;
130
128
return ( ) => slots . default ?.( ) ;
131
129
} ,
0 commit comments