Vue使用markdown编辑器
1.安装
npm install mavon-editor -S
2.main.js全局注册
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
Vue.use(mavonEditor)
3.vue页面使用
<el-form-item label="文章内容">
<mavon-editor ref="md" v-model="form.content" :ishljs="true" @imgAdd="imgAdd"/>
</el-form-item>
imgAdd(pos, $file) {
let $vm = this.$refs.md
const formData = new FormData();
formData.append('file', $file);
axios({
url: 'http://127.0.0.1:9090/files/editor/upload',
method: 'post',
data: formData,
headers: {'Content-Type': 'multipart/form-data'},
}).then((res) => {
var url = res.data.data[0].url
$vm.$img2Url(pos, url);
})
},
4.文章预览
<mavon-editor
class="md"
:value="content"
:subfield="false"
:defaultOpen="'preview'"
:toolbarsFlag="false"
:editable="false"
:scrollStyle="true"
:ishljs="true"
/>