File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change 1- import { ref , Ref } from 'vue' ;
1+ import { readonly , ref } from 'vue' ;
22
33export type MediaQuery = 'normal' | 'minimized' | 'mobile' ;
44const query = ref < MediaQuery > ( 'normal' ) ;
@@ -7,12 +7,14 @@ const detectSize = () => {
77 const el = document . getElementById ( 'app' ) ;
88
99 if ( el ) {
10- query . value =
11- ( getComputedStyle ( el ) . getPropertyValue ( '--media-type' ) . replaceAll ( '"' , '' ) . trim ( ) as MediaQuery ) || 'normal' ;
10+ const mediaType = getComputedStyle ( el ) . getPropertyValue ( '--media-type' ) ;
11+ query . value = ( mediaType . replaceAll ( '"' , '' ) . trim ( ) as MediaQuery ) || 'normal' ;
1212 }
1313} ;
1414
1515window . addEventListener ( 'resize' , detectSize ) ;
16- window . addEventListener ( 'load' , detectSize ) ;
1716
18- export const useMediaQuery = ( ) : Ref < MediaQuery > => query ;
17+ export const useMediaQuery = ( ) => {
18+ detectSize ( ) ;
19+ return readonly ( query ) ;
20+ } ;
You can’t perform that action at this time.
0 commit comments