<style>:
:root {
--mode: 'unknown';
}
@media (prefers-color-scheme: dark) {
:root {
--mode: 'dark';
}
}
@media (prefers-color-scheme: light) {
:root {
--mode: 'light';
}
}
<script>:
data() {
return { mode: '' }
},
created() {
this.mode = getComputedStyle(document.documentElement)
.getPropertyValue('--mode')
.trim()
},
參考:https://www.zhangxinxu.com/wordpress/2020/02/css-params-to-js/