且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Vue:MarkDown编辑器mavon-editor

更新时间:2022-08-22 14:50:48

文档:https://www.npmjs.com/package/mavon-editor

安装依赖

npm install mavon-editor --save

示例

<template>
  <mavonEditor
    ref="md"
    v-bind="$attrs"
    v-on="$listeners"
    @imgAdd="handleImgAdd"
    style="min-height: 600px"
  />
</template>

<script>
/**
 * https://www.npmjs.com/package/mavon-editor
 * 
 * npm install mavon-editor --save
 */
import { mavonEditor } from 'mavon-editor';
import 'mavon-editor/dist/css/index.css';

/**
 * 
 * 事件
 * save
 * change
 */
export default {
  name: '',

  props: [],

  components: {
    mavonEditor,
  },

  data() {
    return {
      
    };
  },

  computed: {},

  methods: {
    // 将图片上传到服务器,返回地址替换到md中
    async handleImgAdd(pos, file) {
      let form = new FormData();
      form.append('file', file);

      const res = await this.$Http.postUploadFile(form);
      console.log(res);
      this.$refs.md.$img2Url(pos, res.data.url);
    },
  },

  created() {},
};
</script>

<style lang="scss" scoped>
</style>

Vue:MarkDown编辑器mavon-editor

参考

vue中使用markdown编辑器