1
- import { watch } from '@vue/runtime-core'
2
- import { defineComponent , h , onMounted , onUpdated , ref , RendererElement , Transition } from 'vue'
1
+ import { defineComponent , h , onMounted , ref , RendererElement , Transition , watch } from 'vue'
3
2
4
3
const CNavGroup = defineComponent ( {
5
4
name : 'CNavGroup' ,
@@ -19,7 +18,7 @@ const CNavGroup = defineComponent({
19
18
} ,
20
19
emits : [ 'visible-change' ] ,
21
20
setup ( props , { slots, emit } ) {
22
- const visible = ref ( props . active || props . visible )
21
+ const visible = ref ( )
23
22
const navGroupRef = ref ( )
24
23
25
24
const visibleGroup = ref ( )
@@ -37,24 +36,29 @@ const CNavGroup = defineComponent({
37
36
const isVisible = ( index : number ) => Boolean ( visibleGroup . value === index )
38
37
39
38
onMounted ( ( ) => {
39
+ visible . value = props . active || props . visible
40
40
if ( props . active || props . visible ) navGroupRef . value . classList . add ( 'show' )
41
41
emit ( 'visible-change' , visible . value )
42
42
} )
43
43
44
- onUpdated ( ( ) => {
45
- visible . value = props . visible
44
+ watch (
45
+ ( ) => props . visible ,
46
+ ( ) => {
47
+ visible . value = props . visible
46
48
47
- if ( visible . value === false ) {
48
- visibleGroup . value = undefined
49
- }
50
- } )
49
+ if ( visible . value === false ) {
50
+ visibleGroup . value = undefined
51
+ }
52
+ } ,
53
+ )
51
54
52
55
watch ( visible , ( ) => {
53
56
emit ( 'visible-change' , visible . value )
54
57
} )
55
58
56
- const handleTogglerClick = function ( ) {
59
+ const handleTogglerClick = ( ) => {
57
60
visible . value = ! visible . value
61
+ emit ( 'visible-change' , visible . value )
58
62
}
59
63
60
64
const handleBeforeEnter = ( el : RendererElement ) => {
0 commit comments