File tree Expand file tree Collapse file tree 1 file changed +14
-9
lines changed Expand file tree Collapse file tree 1 file changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -18,20 +18,25 @@ export function useCssVar(
18
18
if ( ! window )
19
19
return ref ( '' )
20
20
21
- const varRef = ref ( '' )
22
- const elRef = ref ( unref ( el ) || window . document . documentElement )
21
+ const variable = ref ( '' )
22
+ const _el = ref ( el || window . document . documentElement )
23
23
24
- tryOnMounted ( ( ) => {
25
- varRef . value = window . getComputedStyle ( elRef . value ) . getPropertyValue ( prop )
26
- } )
24
+ watch (
25
+ _el ,
26
+ ( ) => {
27
+ if ( _el . value )
28
+ variable . value = window . getComputedStyle ( _el . value ) . getPropertyValue ( prop )
29
+ } ,
30
+ { immediate : true } ,
31
+ )
27
32
28
33
watch (
29
- varRef ,
34
+ variable ,
30
35
( val ) => {
31
- if ( elRef . value ?. style )
32
- elRef . value . style . setProperty ( prop , val )
36
+ if ( _el . value ?. style )
37
+ _el . value . style . setProperty ( prop , val )
33
38
} ,
34
39
)
35
40
36
- return varRef
41
+ return variable
37
42
}
You can’t perform that action at this time.
0 commit comments