index.vue 964 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <template>
  2. <div class="p-4">
  3. <a-button @click="toggleTheme" class="mb-2" type="primary">黑暗主题</a-button>
  4. <MarkDown :value="value" @change="handleChange" ref="markDownRef" />
  5. </div>
  6. </template>
  7. <script lang="ts">
  8. import { defineComponent, ref, unref } from 'vue';
  9. import { MarkDown, MarkDownActionType } from '/@/components/Markdown';
  10. export default defineComponent({
  11. components: { MarkDown },
  12. setup() {
  13. const markDownRef = ref<Nullable<MarkDownActionType>>(null);
  14. const valueRef = ref(`
  15. # title
  16. # content
  17. `);
  18. function toggleTheme() {
  19. const markDown = unref(markDownRef);
  20. if (!markDown) return;
  21. const vditor = markDown.getVditor();
  22. vditor.setTheme('dark');
  23. }
  24. function handleChange(v: string) {
  25. valueRef.value = v;
  26. }
  27. return {
  28. value: valueRef,
  29. toggleTheme,
  30. markDownRef,
  31. handleChange,
  32. };
  33. },
  34. });
  35. </script>