mavon-editor 使用方法以及回显

    <div class="bianji markdown-body">
          <mavon-editor
            ref="md"
            @change="handleMarkdownChange"
            @imgAdd="handleEditorImgAdd"
            @imgDel="imgDel"
            :ishljs="true"
            v-model="form.doc"
          />
        </div>

import { mavonEditor } from "mavon-editor";
import "mavon-editor/dist/css/index.css";
 
 

 

主要点为:图片上传在不经过处理时,maveonEditor 会将其转换成base64图,当再次请求到图片回显时,会是一大段的base64的代码,所以上传图片时要先上传的到服务器,拿到服务器图片链接,这样回显时也会是图片链接。

  handleEditorImgAdd(pos, file){
     var newdate = new FormData();
      newdate.append("file", file);
      pushFileUnload(newdate).then((res) => {  //图片上传到服务器返回图片url 链接
        console.log(res);
        this.$refs.md.$img2Url(pos, res.data.url);  //通过ref插入到文档中
      });
    },

 

posted @ 2020-10-23 18:08  张小中  阅读(4100)  评论(0编辑  收藏  举报