改进 主题获取

This commit is contained in:
ivamp 2023-12-07 22:17:00 +08:00
parent f6a32661c5
commit f397b82111
3 changed files with 13 additions and 6 deletions

8
src/plugins/getTheme.ts Normal file
View File

@ -0,0 +1,8 @@
let matchResult = window.matchMedia('(prefers-color-scheme: dark)');
function getTheme() {
return matchResult.matches ? 'dark' : 'light'
}
export default getTheme()

View File

@ -13,7 +13,7 @@
</div>
<MdEditor
:theme="theme == 'dark' ? 'dark' : 'light'"
:theme="getTheme"
v-model="createData.Content"
/>
@ -60,10 +60,7 @@ import { MdEditor } from "md-editor-v3";
import "md-editor-v3/lib/style.css";
import router from "@/router/index";
import { document } from "@/plugins/api";
import { useTheme } from "vuetify/lib/framework.mjs";
// get current theme
const theme = useTheme().name;
import getTheme from "@/plugins/getTheme";
const created = ref(false);

View File

@ -4,6 +4,8 @@ import { ref } from "vue";
import { document } from "@/plugins/api";
import { MdPreview } from "md-editor-v3";
import LoadingComponent from "@/components/Loading.vue";
import getTheme from "@/plugins/getTheme";
const libraryId = parseInt(router.currentRoute.value.params.LibraryId);
const documentId = parseInt(router.currentRoute.value.params.DocumentId);
@ -36,7 +38,7 @@ document
<div v-else>
<h2>{{ docu.Title }}</h2>
<MdPreview :modelValue="docu.Content" />
<MdPreview :theme="getTheme" :modelValue="docu.Content" />
</div>
</div>
</template>