You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
2.4 KiB

<!-- writing.vue 写作页面-->
<template>
<div class="writing-container">
<div class="editor-container">
<textarea v-model="markdownContent" class="markdown-editor" placeholder="输入 Markdown 内容..."></textarea>
</div>
<div class="preview-container">
<h2>实时预览</h2>
<div class="preview-content" v-html="compiledMarkdown"></div>
</div>
<button class="scroll-to-top" @click="scrollToTop"></button>
</div>
</template>
<script lang="ts" setup>
import { ref, computed } from 'vue';
import { marked } from 'marked';
// 定义一个响应式变量来存储 Markdown 内容
const markdownContent = ref('');
// 使用 marked 库将 Markdown 内容转换为 HTML
const compiledMarkdown = computed(() => {
return marked(markdownContent.value);
});
const scrollToTop = () => {
};
</script>
<style scoped>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background-color: #f0f0f0; /* 可以根据需要调整背景颜色 */
}
.writing-container {
display: flex;
flex-direction: row;
justify-content: space-between;
padding: 20px;
width: 100%;
height: 100vh;
box-sizing: border-box;
position: relative; /* 添加相对定位,以便子元素绝对定位 */
}
.editor-container {
width: 48%;
height: 100%;
box-sizing: border-box;
}
.preview-container {
width: 48%;
height: 100%;
border-left: 1px solid #ccc;
padding-left: 20px;
box-sizing: border-box;
}
.markdown-editor {
width: 100%;
height: calc(100% - 40px); /* 减去 padding 的高度 */
padding: 10px;
box-sizing: border-box;
font-family: monospace;
border: 1px solid #ccc;
border-radius: 5px;
resize: vertical; /* 允许垂直调整大小 */
}
.preview-content {
height: calc(100% - 60px); /* 减去 h2 的高度和 padding */
overflow-y: auto;
white-space: pre-wrap;
word-wrap: break-word;
padding: 10px;
box-sizing: border-box;
}
/* 按钮样式 */
.scroll-to-top {
position: absolute; /* 使用绝对定位 */
bottom: 100px;
right: 20px;
padding: 10px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
z-index: 1000; /* 确保按钮在最上层 */
}
/* 按钮悬停效果 */
.scroll-to-top:hover {
background-color: #0056b3;
}
</style>