<template>
<div id="app">
<textarea v-model="editorContent" @input="updateEditor"></textarea>
<div v-html="compiledMarkdown"></div>
</div>
</template>
<script>
import marked from 'marked';
export default {
data() {
return {
editorContent: '# Welcome to Vue Editor\nWrite your markdown here.'
};
},
computed: {
compiledMarkdown() {
return marked(this.editorContent);
}
},
methods: {
updateEditor(event) {
this.editorContent = event.target.value;
}
}
};
</script>
<style>
#app {
display: flex;
}
textarea {
width: 50%;
height: 100vh;
resize: none;
}
div:nth-child(2) {
width: 50%;
padding: 20px;
border-left: 1px solid #ccc;
}
</style>
模板部分 (<template>
):
textarea
用于输入 Markdown 内容。v-model
绑定 editorContent
数据属性,使输入内容与数据同步。v-html
将编译后的 Markdown 内容显示在右侧的 div
中。脚本部分 (<script>
):
marked
库来解析 Markdown。data
函数返回初始状态,包括默认的编辑器内容。compiledMarkdown
将 editorContent
转换为 HTML。updateEditor
方法,在用户输入时更新 editorContent
。样式部分 (<style>
):
上一篇:vue播放视频
下一篇:antd for vue
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站