提交源文件
This commit is contained in:
33
src/main.js
Normal file
33
src/main.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import { createApp } from "vue";
|
||||
import router from "./router/index.js";
|
||||
import App from "./App.vue";
|
||||
import ElementPlus from "element-plus";
|
||||
import zhCn from "element-plus/es/locale/lang/zh-cn";
|
||||
import "element-plus/dist/index.css";
|
||||
import "element-plus/theme-chalk/dark/css-vars.css";
|
||||
import store from "./store";
|
||||
|
||||
let matchMedia = window.matchMedia("(prefers-color-scheme: light)");
|
||||
setDarkMode(matchMedia.matches);
|
||||
matchMedia.addEventListener("change", function () {
|
||||
console.log(`当前的主题是:${this.matches ? "light" : "dark"}`);
|
||||
setDarkMode(this.matches);
|
||||
});
|
||||
|
||||
// 设置主题模式
|
||||
function setDarkMode(flag) {
|
||||
if (flag) {
|
||||
document.querySelector("#html").classList.add("light");
|
||||
document.querySelector("#html").classList.remove("dark");
|
||||
} else {
|
||||
document.querySelector("#html").classList.add("dark");
|
||||
document.querySelector("#html").classList.remove("light");
|
||||
}
|
||||
}
|
||||
|
||||
const app = createApp(App);
|
||||
|
||||
app.use(router);
|
||||
app.use(store);
|
||||
app.use(ElementPlus, { locale: zhCn });
|
||||
app.mount("#app");
|
||||
Reference in New Issue
Block a user