22
33###
44
5- ### — 穆贵林
5+ ### — 穆贵林
66
7- 2025年02月28日
7+ 2025年03月6日
8+
9+ ###### CSDN:[ JS媒体查询之matchMedia API 实现跟随系统主题色切换效果] ( https://blog.csdn.net/muguli2008/article/details/144797009 )
810
911
1012
@@ -53,7 +55,7 @@ Window 的 [matchMedia()](https://developer.mozilla.org/zh-CN/docs/Web/API/Windo
5355 --bg-color : #333 ;
5456 }
5557
56- html [data-theme = " ligth " ] {
58+ html [data-theme = " light " ] {
5759 --text-color : #333 ;
5860 --bg-color : #fff ;
5961 }
@@ -101,7 +103,7 @@ Window 的 [matchMedia()](https://developer.mozilla.org/zh-CN/docs/Web/API/Windo
101103 <hr >
102104
103105 <select name =" theme" id =" theme" >
104- <option value =" ligth " >亮色</option >
106+ <option value =" light " >亮色</option >
105107 <option value =" dark" >暗色</option >
106108 <option value =" os" >系统跟随</option >
107109 <option value =" red" >红色</option >
@@ -119,13 +121,13 @@ Window 的 [matchMedia()](https://developer.mozilla.org/zh-CN/docs/Web/API/Windo
119121
120122 // 设置主题
121123 const setTheme = (theme ) => {
122- document .documentElement .setAttribute (' data-theme' , Object .prototype .toString .call (theme) === ' [object MediaQueryListEvent]' ? metch .matches ? ' dark' : ' ligth ' : theme);
124+ document .documentElement .setAttribute (' data-theme' , Object .prototype .toString .call (theme) === ' [object MediaQueryListEvent]' ? metch .matches ? ' dark' : ' light ' : theme);
123125 };
124126
125127 // 监听主题切换
126128 theme .addEventListener (' change' , (e ) => {
127129 if (' os' === e .target .value ) {
128- setTheme (metch .matches ? ' dark' : ' ligth ' );
130+ setTheme (metch .matches ? ' dark' : ' light ' );
129131 // 监听系统主题切换
130132 metch .addEventListener (' change' , setTheme);
131133 } else {
@@ -202,7 +204,7 @@ export function useTheme() {
202204 <h1 >JS媒体查询之matchMedia API 实现跟随系统主题色切换效果</h1 >
203205 <hr >
204206 <select v-model =" theme" >
205- <option value =" ligth " >亮色</option >
207+ <option value =" light " >亮色</option >
206208 <option value =" dark" >暗色</option >
207209 <option value =" os" >系统跟随</option >
208210 <option value =" red" >红色</option >
@@ -223,7 +225,7 @@ export function useTheme() {
223225 --bg-color : #333 ;
224226 }
225227
226- html [data-theme = " ligth " ] {
228+ html [data-theme = " light " ] {
227229 --text-color : #333 ;
228230 --bg-color : #fff ;
229231 }
0 commit comments