'md编辑器上传图片'

pull/78/head
lin-xin 2018-04-11 11:29:55 +08:00
parent a0c5d89f59
commit 6531f7fac9
2 changed files with 36 additions and 5 deletions

View File

@ -61,11 +61,11 @@
}, },
{ {
index: 'vueeditor', index: 'vueeditor',
title: '编辑器' title: '富文本编辑器'
}, },
{ {
index: 'markdown', index: 'markdown',
title: 'markdown' title: 'markdown编辑器'
}, },
{ {
index: 'upload', index: 'upload',

View File

@ -11,8 +11,8 @@
mavonEditor基于Vue的markdown编辑器 mavonEditor基于Vue的markdown编辑器
访问地址<a href="https://github.com/hinesboy/mavonEditor" target="_blank">mavonEditor</a> 访问地址<a href="https://github.com/hinesboy/mavonEditor" target="_blank">mavonEditor</a>
</div> </div>
<mavon-editor v-model="content" codeStyle="tomorrow-night-blue" style="min-height: 600px"/> <mavon-editor v-model="content" ref="md" @imgAdd="$imgAdd" @change="change" style="min-height: 600px"/>
<el-button class="editor-btn" type="primary" @click="submit"></el-button>
</div> </div>
</div> </div>
</template> </template>
@ -24,12 +24,43 @@
data: function(){ data: function(){
return { return {
content:'', content:'',
html:'',
configs: { configs: {
} }
} }
}, },
components: { components: {
mavonEditor mavonEditor
},
methods: {
// md
$imgAdd(pos, $file){
var formdata = new FormData();
formdata.append('file', $file);
//
this.$axios({
url: '/common/upload',
method: 'post',
data: formdata,
headers: { 'Content-Type': 'multipart/form-data' },
}).then((url) => {
this.$refs.md.$img2Url(pos, url);
})
},
change(value, render){
// render markdown
this.html = render;
},
submit(){
console.log(this.content);
console.log(this.html);
this.$message.success('提交成功!');
}
} }
} }
</script> </script>
<style scoped>
.editor-btn{
margin-top: 20px;
}
</style>