Skip to content

Commit 3c3225a

Browse files
author
F-loat
committed
add examples
1 parent ed76a34 commit 3c3225a

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed

examples/index.vue

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<template>
2+
<div class="demo-wrap">
3+
<div class="editor-wrap">
4+
<div class="editor">
5+
<h4 class="title">默认配置&禁用自动初始化</h4>
6+
<markdown-editor
7+
v-model="content"
8+
ref="markdownEditor"
9+
:autoinit="false"></markdown-editor>
10+
</div>
11+
<div class="editor">
12+
<h4 class="title">开启代码高亮&使用github的markdown样式</h4>
13+
<markdown-editor
14+
v-model="content"
15+
:highlight="true"
16+
preview-class="markdown-body"></markdown-editor>
17+
</div>
18+
<div class="editor theme">
19+
<h4 class="title">自定义代码高亮主题</h4>
20+
<markdown-editor
21+
v-model="content"
22+
:highlight="true"
23+
preview-class="markdown-body"></markdown-editor>
24+
</div>
25+
<div class="editor">
26+
<h4 class="title">隐藏底部统计栏&修改工具栏</h4>
27+
<markdown-editor
28+
v-model="content"
29+
:configs="configs"></markdown-editor>
30+
</div>
31+
</div>
32+
<div class="button-wrap">
33+
<button type="button" @click="handleOutputMARKDOWN">输出MARKDOWN</button>
34+
<button type="button" @click="handleOutputHTML">输出HTML</button>
35+
<div v-text="output"></div>
36+
<div v-html="output" v-show="type === 'html'" class="markdown-body"></div>
37+
</div>
38+
</div>
39+
</template>
40+
41+
<script>
42+
import markdownEditor from 'vue-simplemde/src/markdown-editor';
43+
export default {
44+
name: 'index',
45+
components: {
46+
markdownEditor,
47+
},
48+
data() {
49+
return {
50+
content: '``` \nconsole.log("lalala") \n```',
51+
configs: {
52+
status: false,
53+
toolbar: ['image'],
54+
},
55+
output: '',
56+
type: 'markdown',
57+
};
58+
},
59+
computed: {
60+
simplemde() {
61+
return this.$refs.markdownEditor.simplemde;
62+
},
63+
},
64+
mounted() {
65+
this.$nextTick(() => {
66+
this.$refs.markdownEditor.initialize();
67+
});
68+
},
69+
methods: {
70+
handleInput(val) {
71+
this.output = val;
72+
},
73+
handleOutputHTML() {
74+
this.type = 'html';
75+
this.output = this.simplemde.markdown(this.content);
76+
},
77+
handleOutputMARKDOWN() {
78+
this.type = 'markdown';
79+
this.output = this.content;
80+
},
81+
},
82+
};
83+
</script>
84+
85+
<style>
86+
@import '~simplemde/dist/simplemde.min.css';
87+
@import '~highlight.js/styles/atom-one-dark.css';
88+
@import '~github-markdown-css';
89+
90+
body {
91+
margin: 0;
92+
padding: 0;
93+
}
94+
.button-wrap {
95+
padding: 20px;
96+
}
97+
.editor-wrap {
98+
width: 100%;
99+
max-width: 900px;
100+
padding: 0 10px;
101+
float: left;
102+
}
103+
.editor {
104+
padding: 10px;
105+
box-sizing: border-box;
106+
}
107+
.title {
108+
text-align: center;
109+
}
110+
.markdown-editor .CodeMirror {
111+
height: 200px;
112+
}
113+
/*修改代码块背景色及字体颜色*/
114+
.theme .editor-preview-side pre, .theme .editor-preview pre{
115+
color: #abb2bf !important;
116+
background: #282c34 !important;
117+
}
118+
</style>

0 commit comments

Comments
 (0)