File tree 2 files changed +36
-5
lines changed
2 files changed +36
-5
lines changed Original file line number Diff line number Diff line change 61
61
},
62
62
{
63
63
index: ' vueeditor' ,
64
- title: ' 编辑器 '
64
+ title: ' 富文本编辑器 '
65
65
},
66
66
{
67
67
index: ' markdown' ,
68
- title: ' markdown '
68
+ title: ' markdown编辑器 '
69
69
},
70
70
{
71
71
index: ' upload' ,
Original file line number Diff line number Diff line change 11
11
mavonEditor:基于Vue的markdown编辑器。
12
12
访问地址:<a href =" https://github.com/hinesboy/mavonEditor" target =" _blank" >mavonEditor</a >
13
13
</div >
14
- <mavon-editor v-model =" content" codeStyle = " tomorrow-night-blue " style =" min-height : 600px " />
15
-
14
+ <mavon-editor v-model =" content" ref = " md " @imgAdd = " $imgAdd " @change = " change " style =" min-height : 600px " />
15
+ < el-button class = " editor-btn " type = " primary " @click = " submit " >提交</ el-button >
16
16
</div >
17
17
</div >
18
18
</template >
24
24
data : function (){
25
25
return {
26
26
content: ' ' ,
27
+ html: ' ' ,
27
28
configs: {
28
29
}
29
30
}
30
31
},
31
32
components: {
32
33
mavonEditor
34
+ },
35
+ methods: {
36
+ // 将图片上传到服务器,返回地址替换到md中
37
+ $imgAdd (pos, $file){
38
+ var formdata = new FormData ();
39
+ formdata .append (' file' , $file);
40
+ // 这里没有服务器供大家尝试,可将下面上传接口替换为你自己的服务器接口
41
+ this .$axios ({
42
+ url: ' /common/upload' ,
43
+ method: ' post' ,
44
+ data: formdata,
45
+ headers: { ' Content-Type' : ' multipart/form-data' },
46
+ }).then ((url ) => {
47
+ this .$refs .md .$img2Url (pos, url);
48
+ })
49
+ },
50
+ change (value , render ){
51
+ // render 为 markdown 解析后的结果
52
+ this .html = render;
53
+ },
54
+ submit (){
55
+ console .log (this .content );
56
+ console .log (this .html );
57
+ this .$message .success (' 提交成功!' );
58
+ }
33
59
}
34
60
}
35
- </script >
61
+ </script >
62
+ <style scoped>
63
+ .editor-btn {
64
+ margin-top : 20px ;
65
+ }
66
+ </style >
You can’t perform that action at this time.
0 commit comments